I'll give the converter a try.
rainwarrior wrote:
I responded to your claim about the efficiency of classes not to argue with you, but for the benefit of anyone else reading because I think you're spreading misinformation.
But your example wasn't something that you would find in real object orientation. It was just an example of using classes for the sake of using classes.
A real object oriented approach would be something like this (written in pseudo code):
Code:
class Character
{
int X;
int Y;
bool IsActive;
virtual void Move();
}
class Player : Character
{
int Energy;
override void Move();
}
class WalkingOpponent : Character
{
Direction CurrentWalkingDirection;
override void Move();
}
class WalkingOpponent : Character
{
int JumpVelocity;
override void Move();
}
// Somewhere else:
Player Player;
Character *Opponents[5] = { null, ... };
This is how you use object orientation.
Your example wasn't even valid as a simple example since it wasn't object orientation at all. As your member variables, you basically used a bunch of global variables (encapsulated into the class, but nevertheless a bunch of glorified global variables) and the only thing that your class objects actually included was an index to reference these global arrays. That's not what object orientation is about.
Why did you even declare a member in the class to begin with? If the class has only one member (and will only ever have this one member since the actual data is supposed to be in the static arrays) and this member is nothing but the index/ID/slot for all the arrays, then why don't you declare each index that you need as a simple global integer to begin with? Just so that you can call
myObject.DoStuff() instead of
DoStuff(myIndex)?
Sorry, your code is not clean object orientation. That's a bunch of static arrays and a bunch of indices to use the static arrays. The class is basically nothing but a glorified namespace here.
rainwarrior wrote:
If you're someone who has been using C++ for years and has seen its utility, the ability to use it with such a limited processor like the 6502 might be a really interesting prospect. Do you really think I owe you a lesson on why C++ is useful? Can't you just let others talk about it even if you don't understand why they're interested? It's quite exhausting to have you belligerently demand that we justify our interest in it.
You seem to be under the impression that I haven't used it myself. I'm not a hobby programmer, I do programming for a living. While I haven't used C++ itself for a few years now (after working with it for three years), I work with C# which has a similar object oriented approach, so I know what I'm talking about.
And I can tell you this:
If you use a
clean object oriented approach as my example above, my argument still stands: With this approach you have indirect access for everything, meaning it is unsuitable for an NES game. And nobody has tried to question this until now.
If you use the approach from your example, then this has nothing to do with object orientation anymore. The class as a container for static arrays with the only non-static member being an index for said static arrays is still pure functional C-like programming with the only difference being that the class serves as a namespace for the arrays and the index doesn't need to be passed to the function (instead, you have to precede the object name in front of every function call).
So, no, your example is
not a description how C++ can
still be useful for the NES without any overhead. Your example just shows that you can put a bunch of global stuff into a class just for the sake of using a class.
pstalcup wrote:
DRW, you seem to be willing to discount the fact that it is easier to write and develop modern C++ than old C (which is the type of C you necessarily have to write using cc65).
That's total nonsense. I never said that.
In fact, the contrary is true: It is much, much easier and cleaner to develop stuff with a good object oriented model, occasional templates, a good standard framework and variables as local and as temporary as necessary.
And this is what I have been doing almost every workday in the past nine years or so.
What I want to say regarding the NES is: All the neat things that make your programming life easier in a modern environment just cannot be used on the NES without a huge performance hit. If you want to write a game for the NES, you need to do a bunch of dirty stuff like:
- using macros
- declaring a struct with a bunch of arrays instead of an array of a struct
- functions whose "parameters" are global variables that are set before each function call (with macros, so you don't forget to set any variable) instead of actual parameters.
And keeping this in mind, a clean object oriented character and level model will be totally unfitting for an NES game.
The only way you could efficiently use classes on the NES is by filling it with a bunch of static variables which defeats to purpose of using classes in the first place.
Yes, C++ has some features that don't produce any overhead: Inline functions, const expressions, reference variables, local variables that can be put anywhere into a function instead of just the start of a block.
But firstly, these little things are barely enough to demand a full C++ compiler since it's basically just syntax sugar.
And secondly, the usefulness of these things is mundane anyway. There's nothing to "talk" or "discuss" about it. Yes, inline functions are better than macros. Period.
But what
is worthy of discussion: Is it worth creating a full C++ compiler for the NES in the first place? Or will the things that really
define C++ over C be the stuff that cannot be used in an NES game efficiently anyway, so we should rather spend time improving the existing C compiler instead?
And I think: The really strong, defining features of C++, which are object orientation, templates and the C++ standard library, are all things that you couldn't (or shouldn't) really use in an NES game anyway.
(If we're talking about a tool that converts x86 Assembly to 6502 Assembly, so that you can use a professional compiler that already exists: Now, that's a totally different topic of course since the C++ features are not an issue here because GCC already has them while the conversion tools only needs to convert raw Assembly into another form of raw Assembly. But a new C++ compiler for the NES: Waste of time.)
That's my standpoint. My standpoint is not "I discount the fact that it is easier to write and develop modern C++ than old C."
pstalcup wrote:
I have not completed a full NES game, so my opinion is one of a professional software developer, rather than a hobby game developer. I do believe my points stand, though.
Well, my opinion is that of a professional software developer who also
has completed a full NES game as a hobby project. And I must say: All your statements about modern programming are of course true, but you misunderstood what I wanted to say.
Rainwarrior's example doesn't justify object orientation to begin with since he just uses the class as a simple container for static variables.
And my above object oriented example would be unfitting for an NES game since the compiler would have no choice but to use indirect access every time a member is referenced. Do you disagree with this?