LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2006, 08:23 AM   #16
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138

Quote:
Surely the frequency at which the sprite changes frames is an attribute of the sprite itself. Something that can be changed by another class, but which is a property of the sprite itself.

All those classes are more like glorified structures at the moment. The reason for your specific question is very simple: I'm not sure how the sprite speed will integrate with the main program loop, so I kept that out of the class. As I've not yet come to the point as how the whole thing will come out...

A lot of things are going on in my mind. Unfortunately I cannot program all day long because I have other work to do.

I guess the point of my using classes is to simplify the main () function and not to achieve true object orientation (ala abstraction, encapsulation, inheritance etc. etc.). I've deliberately kept the classes simple because I don't know how it will work out in the long run.

Quote:
line 97 store pallette in hardware
It's been commented out in that code? Also I guess since I'll be using 16-bit or 32-bit exclusively there's no question of storing palette information.

Also I don't understand the need for checking the video info for all those flags. If I simply use some flags and those cannot be set, I think SDL will ignore them (at least that's what I read somewhere). Not ideal, but at least it's not totally critical that way.

Last edited by vharishankar; 07-31-2006 at 08:31 AM.
 
Old 07-31-2006, 08:47 AM   #17
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
I thought I should explain my SDLSprite class a bit more:

It's not meant to be a full fledged sprite handling class. Here's how it works at the moment. It just takes an image containing all the frames of the animation stored horizontally and then splits it up based on the frame width specified and stores each frame separately. You just need to call the render function specifying the frame index to draw a particular frame at the moment. The calling function should do the actual animation work involved with multiple calls to renderframe every frame.

It's just that thin. The advantage is that this class can also be used for other purposes than just sprite animation. It could also be used as a mere array of surfaces for instance.

Last edited by vharishankar; 07-31-2006 at 08:48 AM.
 
Old 07-31-2006, 10:20 AM   #18
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
I suggest that you should put all of your classes in the "SDL" namespace and strip the prefix off, since you are essentially using that prefix to do the same thing as a namespace.

I did a set of C++ wrappers to get myself used to the API, based on a set of Java graphics wrappers for games a professor of mine already wrote. It was also my first real introduction to library C++ coding minus all of the predone stuff in Visual Studio (blech).

I actually think it is more fun to build your own engine than to use a prebuilt one.
 
Old 07-31-2006, 10:34 AM   #19
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Tuxdev, thanks for the tip.

Yes, I should probably do all those pretty things like namespaces etc. At the moment I'm sort of adding functionality as I go on.

I agree with you on the engine development part. It is fun. And part of the reason why I chose not to use a prebuilt one.

Again, my classes aren't pretty or even very feature rich, but it's got me developing and reducing the code clutter and that's my main objective anyway. To be able to write SDL programs without cluttering my program functions with SDL calls and declarations.

My philosophy is very simple - I have no programming philosophies. OO or otherwise, I tend to do what works best for me. I don't want to particularly stick to one kind of way which is why I guess you might find my coding practices a bit peculiar as in neither here nor there.

The main purpose of using C++ classes in my programs is not to get Object Oriented programming (Note: the concept of OO programming and using classes in code is completely different from one another) concepts into my code but merely to reduce code clutter.

That's why I said my C++ classes are more like glorified structures.

Last edited by vharishankar; 07-31-2006 at 10:39 AM.
 
Old 07-31-2006, 11:22 AM   #20
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by Harishankar
It's been commented out in that code?...
Yes it has and so should other things in the code as for this part of the engine it's just using SDL as an means to get and show input nothing more as OpenGL is the renderer.

Ok if you don't at least try and give SDL hardware flags you app is going to suffer. You may have a graphic card with good memory and gpu but if you don't set the flags you will be using software to emulate the hardware, which doesn't make an sense.

You keep saying your not going to use C++ features, so why use C++ and not C? You could then carry on your structure programming. OO makes games programming easier, everything (or nearly) is an object. If you are talking about clean code how about all characters inhert from a base class Object. Objects are created an pushed into a std::vector and the draw looks something like:

Code:
void Graphics::draw()
{
for(iter = some.begin();iter!=some.end();++iter)(*iter)->draw();
}
This is a very simple example which does not show clipping of objects etc.
 
Old 07-31-2006, 10:32 PM   #21
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Yes, for precisely the reason you mentioned I use C++. I don't have an objection to mixing and matching methods. Probably what I meant was I didn't want to get bogged down by worrying about coding mechanics particularly when it comes to philosophical rather than practical design decisions and would rather concentrate on the logic.

Yes, I guess that most C++ libraries you find have a good inheritance and abstraction structure in place and that's why I said I use classes mainly as a way to group related functions and variables and to do automatic cleanup through destructors rather than any real intention of doing OOP. It's not that I'm anti-OOP, but I just don't have a preference and am not averse to mixing and matching methods if I can get the final result.

Last edited by vharishankar; 07-31-2006 at 10:35 PM.
 
Old 08-01-2006, 11:39 AM   #22
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
To me, it seems a lot easier to code in a OOP-like fasion in C++ than in C, simply because of all the stuff that the language provides. Really, OOP to me is inheritance + RAII, and it is a lot easier to program an inheritance structure that models the problem. Sort of like "When in Rome, do as the Romans do" because it is harder not to.

In one of my personal projects, I'm trying to port a Java game to either C or C++ with SDL. I started out using C++, but after I had done quite a bit of it, I realized that I wasn't using any of the C++ features that weren't already in C, so I switched. It was pretty ironic because it was programmed in C in the first place! It'll probably grow into C++ eventually when I get past playing catch-up.
 
Old 08-01-2006, 11:52 AM   #23
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Game programming uses a lot of OOP. Unfortunately I think a beginner can get too bogged down into planning and implementing an OOP-based structure rather than designing the game logic and code itself. That's why I think many people love C. It just lets you code quick and dirty (not that C++ doesn't - it's just a psychological factor I guess - Java shoves OO down your throat whether you like it or not - C++ doesn't).

As I said, I find that planning the OOP structure is a rather tedious process and requires immense planning and forethought. For instance, why should a certain class be derived instead of containing another class? Where would you need abstract classes with virtual functions? Why should some classes encapsulate certain functionality and not other functionality? Which classes "own" certain logic and which others shouldn't mess with that logic? How much logic should a class hide from others and how much should it show?

Instead of answering questions like the ones I mentioned I think it's better to just write code and do it the way you think it should be done rather than trying to comply with real or imagined philosophical standards

Last edited by vharishankar; 08-01-2006 at 11:54 AM.
 
Old 08-01-2006, 12:28 PM   #24
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Definitely. That project I mentioned I used C++ so that I could have the freestyle of C with all of the stuff in C++ that makes life easier. A lot of times, the natural OOP solution pops into my head by trying to figure out what the problem exactly is. So those questions are answered before I get to asking them.

Last edited by tuxdev; 08-01-2006 at 12:29 PM.
 
Old 08-01-2006, 01:25 PM   #25
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Unfortunately I think a beginner can get too bogged down into planning and implementing an OOP-based structure rather than designing the game logic and code itself.
Which brings you full circle to your orignal question which I did not comment on.
Quote:
My question - is it better to "reinvent" the wheel...
If you have never made a game, read tonnes of books on the subject or just want to make a game then I would say no. Use a game engine or rendering engine that is freely available.


Quote:
...I find that planning the OOP structure is a rather tedious process and requires immense planning and forethought...
Any game (or medium to large project) requires this; otherwise what you create will be mashed together in a horrible mess, with hard to find bugs, hard to follow logic and hard to follow flow of control.


Quote:
Instead of answering questions like the ones I mentioned I think it's better to just write code and do it the way you think it should be done rather than trying to comply with real or imagined philosophical standards.
Where as I and ALL game compaines think not. What your are describing is prototyping, from which you find the way you want it to go and what you want to implement.


At the risk of repeating myself lol
Quote:
...The problem is you need to design anything like making a game or a framework, heres the catch22 how can you design when you don't know the API. This is something which I have faced many times, what I would say is keep it "dirty" and do not strive for a reusable framework; instead learn the API and then create the framework. In the end this will help you create a very good reusable piece.

Last edited by dmail; 08-01-2006 at 01:36 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Geeks Unite!!! DanTaylor LinuxQuestions.org Member Intro 1 01-15-2006 03:22 AM
Online stores for geeks GNUROCKS General 6 01-31-2005 03:02 AM
Why do Geeks have Glasses? HadesThunder General 50 09-05-2004 09:50 AM
Here I come, geeks or not geeks has2k1 LinuxQuestions.org Member Intro 1 06-04-2004 05:58 PM
Calling all wireless geeks!!! finegan Linux - Hardware 9 03-13-2003 01:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration