News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Learn by driving and code by coding…

Started by emaxectranspoorte, January 11, 2009, 06:36:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

emaxectranspoorte

Please read the following lines: (isn't it wonderful?)
"Another point was, that I wanted to learn object oriented design and object oriented programming. Most elements of a transport simulation are easy to recognize as objects (vehicles, goods, buildings, routes, schedules ...), so I decided to make Simutrans my learning project for OOD and OOP.
After programming C for a long time I wanted to learn C++ and needed a OO project to learn C++."
This citation is copyrighted by Hj. Malthaner himself. I found it in wikipedia. Here's the link to it
http://www.simugraph.com/simutrans-web/en/history/index.html
In my opinion, it's quite amazing how much Simutrans has evolved since he first created it. I've no idea of what sort of programming languages are now used to develop it, as it is now. Still I think it should be C/C++.
I'm learning C, C++, along with assembly language, as well. An Assembler is able to call API functions, written in C. Vlad Pirogov: "Windows programming is based on the calls to API functions. The number of such functions is about 2,000. Most of the programs will consist of such calls. All interaction with peripheral devices and operating system resources will be carried out using these functions."
The executable in assembly is very small. I'm using as a reference, at the moment, Vlad Pirogov's: The Assembly Programming Master Book.
He says:
"Aiming to prove that writing programs for Windows in the Assembly language is no more difficult than writing the same programs using C/C++, this guide shows how Assembly code is actually more compact and executes faster."
I would like to follow Malthaner's pathway, like learning OOP and OOD, while programming something for Simutrans. The Assembly has OOP too, as you can see by yourself, when creating a window: "Based on the registered window class, it is possible to create an instance of the window using the CreateWindowExA (or CreateWindowA) function. As can be easily noticed, this is similar to the object-oriented programming paradigm." That means you can create more instances!
I'm about now at Part II Chapter 7: Examples of Simple Programs, and this is one of the programs I compiled (the source code, text3.asm and text3.inc are attached here).
The result of this program is outputting a vertical text on the screen. With some small changes, in the textDouble.asm, the text is spinning on the screen! (The spinning effect is present only if something happens to the window, like moving/resizing. Can you guess why?) The exe will have only 4Kb! (sorry about not providing the *.exe files, because it might be an issue of portability. Assembling and linking have to be done on the local machines. This is a limitation of  any Assembler, anyway).
The above program in C/C++ will be larger, but it still is doing the same, calling those API functions. My idea is converting C++ programs in Assembly. I'd like to learn this, as a hobby.
With your help, I would like to try it, with some patching up, starting with very small things, of course.
I guess this will help my learning, a lot. 

P.S. The files are attached as mysource.zip.


jamespetts

Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

emaxectranspoorte

#2
Thank you jamesspetts, for your kind response.

I just want to improve by learning and doing something for Simutrans. :)

isidoro

Assembly may be faster, but it is much more difficult to maintain.  But the main problem is that assembly is specific to one kind of processor.  That was the main reason to invent C.  And talking about API, that's specific to Windows.  In a multiplatform project, abstraction libraries are used, like SDL.  Translation to local APIs is done there.

Ashley

While I agree that the best way to learn how to code in any language is by doing (with close attention to documentation) I would recommend you not to start playing with assembly language until you have at least mastered C. It is, as you say yourself, much much less portable than C and there are very few projects written in it. The only reason it compiles to a smaller binary than C is because it isn't as portable, and it's harder to write (so your efforts produce a smaller overall result).

A decent C/C++ compiler will produce bytecode of a similar efficiency to a well-coded assembly program, and is a lot easier and quicker to produce (and will run on a lot more systems). You would, in my opinion, be better off learning C/C++ and getting stuck in to programming something in Simutrans, there's lots to do from what I gather :)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Spike

Cool that my old writing can still inspire people :)

Just a few notes:

Simutrans, at least the early sources, used inheritance often. Later it showed that inheritance is a very strict relation, and difficult to change in a bigger project.

Nowadays I'd use more shallow class hierarchies, and delegation to provide the needed variation. Design patterns become popular a bit too late for me and Simutrans, but I think each aspiring object oriented designer should take a good read of those - they really will influence your software design skills, and usually in a very positive way.

OOP can be done in many languages, but some support it better than others. If you are genuinely new, I'd suggest to look into Java and also Smalltalk. Smalltalk uses a radically different approach to OOP than C++ or Java do, and I think it's good to have seen that too.

Good luck and success with learning :)

@Timothy:

Yes, at some point gcc produced better code than my old assembly routines. That's when they became obsolete. There had always been C replacements for those, though, to maintain better portability.

emaxectranspoorte

Thanks very much for your response, support and understanding. I am very pleased that you told me what to learn and improve on. :)

I know I'm new in programming, but not that new in playing Simutrans. :) It's my hobby for about 2 years ago, and I've been witnessing it's development, and enjoyed every new paks, stables, nightlies, and the new perfect landscapes. All these are really challanging for me.

Thanks, again, for your suggestions and for the hint with Smalltalk. :)

Best Regards,

emaxectranspoorte

lukesleftleg

Oh wow, I didn't notice this thread until just now.

I too am learning OOP as part of the university degree I'm doing right now (Bsc Multimedia and Digital Systems).

I've actually been programming for years, but never all that seriously. Mostly using various versions of Basic, although some C and Pascal, but I've not done any object-oriented programming until I started this degree.

We're learning Java, although I think we'll be doing a number of languages by the end, but I must say, I'm quite impressed with Java so far. Not so much on speed, but more from the point of view of understanding what objects are all about.

Anyway, I just wanted to say that I read those same words about a week or so ago, and was similarly inspired.
That was all really.

I kind of had it in my head to maybe try some sort of transport simulator for my final year project, and that was around the time I came across Simutrans.
We'll see, but maybe once they're done cramming all this information into my head, I'll be able to contribute to Sumutrans too. :)