Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1412073 Posts in 69447 Topics- by 58484 Members - Latest Member: bigdog243

June 26, 2024, 02:40:12 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Programming Languages
Pages: 1 2 3 [4]
Print
Author Topic: Programming Languages  (Read 13117 times)
Nitro Crate
Level 3
***



View Profile
« Reply #60 on: December 29, 2008, 12:22:54 PM »

This has made me feel a little like putting a tutorial together about the actor model and/or using event systems and message passing in general. It's one of the things which I hadn't learned very much of in programming classes or from online tutorials, but the clarity of the metaphor for the sake of games is almost on par with object-orientation.

My first games, after I had learned enough to draw things on the screen and push them around, didn't use any events at all and decided on things like counting score and respawning enemies by hard-coding behavior into the main program loop. Things are a lot more clean if you have a seperate message-passing system in place, and I don't think current educational material highlights this enough.

Please do, I'm having trouble understanding this model. :/
I can't figure out if I'm already using it or not.
Logged
increpare
Guest
« Reply #61 on: January 02, 2009, 02:42:32 AM »

One other random question, given that we're here.  For computer games, one of the slight troubles with the OO method is the fact that many objects are unique (the player say, or a particular boss); sometimes it feels like overkill to have a class that there's only ever going to be one instance of any particular class.  It is just a matter of defining a class, then declaring an instance of it, but still.  One one occasion, instead of having a virtual 'entity' class with virtual 'move' and 'collide' functions, I just had the move and collide functions be member variables.  I found this approach to be quite liberating at the time when i was using it.

The code looked like this:

Code:
levelEntities :: [Entity]
levelEntities=[
      Entity{pos=(1,1), movement=stayStill, collide=playercollide},
      Entity{pos=(5,5), movement=moveUpDown, collide=unstdcollide }, 
      Entity{pos=(5,6), movement=moveLeftRight, collide=unstdcollide }, 
      Entity{pos=(5,7), movement=moveClockwise, collide=stdcollide   }, 
      Entity{pos=(5,8), movement=moveLeftRight, collide=unstdcollide }, 
      Entity{pos=(5,9), movement=moveLeftRight, collide=unstdcollide } 
      ]

where the movement and collision functions were defined elsewhere. (I guess for larger projects you could use lambda-expressions or some other sort of in-line declarations to keep things grouped together).

I'm inclined to think, on the basis of this, that games where every object is more-or-less unique in its behaviour (where the OO inheritance tree wouldn't be more than one level deep, say) are better dealt with in other ways.

I've seen this sort of method talked about in effective C++, I think; I don't know if it has a name as such, though.
Logged
muku
Level 10
*****


View Profile
« Reply #62 on: January 02, 2009, 06:33:47 AM »

I think this is heading towards component-based programming, where every entity is created equal and is distinguished from others only by the list of components that are associated with it. At the extreme, you don't even have an Entity class anymore; an Entity is just an integer (an id) by which you can look up its components in some hashtable or somesuch.

I read about this model a while back and tried to utilize it for my roguelike/Reddenhurst engine. It was an interesting experience for sure, and I'm quite sure that I haven't harnessed the model for its full utility yet. It's quite difficult to break out of the classic OOP paradigm and use such a technique; much of what one needs to do runs quite contrary to everything I've learned about object-oriented design in the last decade. So I really had to force myself to do things differently this time, and one always learns a lot this way.

Here's a quite interesting introductory article about the technique: http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/
It's by a guy who used it on a Tony Hawk game.
Logged
increpare
Guest
« Reply #63 on: January 02, 2009, 06:59:19 AM »

It's quite difficult to break out of the classic OOP paradigm and use such a technique; much of what one needs to do runs quite contrary to everything I've learned about object-oriented design in the last decade.
Not using an OO language helped me, heh.

I'll think more about what you've said, and check out that article.
Logged
muku
Level 10
*****


View Profile
« Reply #64 on: January 02, 2009, 07:13:29 AM »

It's quite difficult to break out of the classic OOP paradigm and use such a technique; much of what one needs to do runs quite contrary to everything I've learned about object-oriented design in the last decade.
Not using an OO language helped me, heh.

Understandably. Smiley

I'm very interested in alternative paradigms, especially functional programming, and I learned me some Haskell, OCaml, Lisp etcetera. I also think that my programming style is leaning more towards functional than that of many other people, even in more OOP-oriented languages; I just love using things like map and filter or anonymous functions or closures, and I've learned that immutable state is often a very good thing.

Still, for games which simulate a number of semi-independent entities (i.e. almost all games), I've always felt that OOP is a very natural paradigm. I think you know a thing or two about how involved it is to set up an entity list with changing state in Haskell -- or did you not find this to be an issue? It was always my impression that this would be quite a bit more complicated than in a mutable state OOP language.

Plus, I do have a lot of knowledge invested in OOP. It took me the better part of 10 years to become good at object-oriented design, so that's something I wouldn't want to simply throw out of the window. Still: the right tool for every job, I say.
Logged
increpare
Guest
« Reply #65 on: January 02, 2009, 07:47:33 AM »

I think you know a thing or two about how involved it is to set up an entity list with changing state in Haskell -- or did you not find this to be an issue?
It wasn't an issue for me; Endless Cavern had a reasonable amount of imperative stuff implemented with the state monad.

The least pleasant aspect was actually dealing with random generation (having to propagate random numbers to the each leaf in a tree, for instance, isn't something I was able to think of a way to do elegantly). 

Have you checked out FRP at all yourself?  This is meant to be the functional answer to mutability in interactive software.

Functional people speak of memoization sometimes, but I've never managed to pin one down and get them to explain how to do it in haskell, nor figure it out myself.
« Last Edit: January 03, 2009, 02:01:22 AM by increpare » Logged
muku
Level 10
*****


View Profile
« Reply #66 on: January 02, 2009, 08:40:04 AM »

Have you checked out FRP at all yourself?  This is meant to be the functional answer to mutability in interactive software.

Not at all, I only know what the Wikipedia article you linked to recently told me. It sounds like an interesting concept, though it's hard to tell what it's all really about without reading something more in-depth or, indeed, seeing some code.

As for memoization in Haskell: good question, I don't know. I trust you have read this here?
Logged
increpare
Guest
« Reply #67 on: January 02, 2009, 09:00:36 AM »

Not at all, I only know what the Wikipedia article you linked to recently told me. It sounds like an interesting concept, though it's hard to tell what it's all really about without reading something more in-depth or, indeed, seeing some code.
A lot of the stuff is work-in-progress, so it can be a pain trying to track down everything needed to compile.  I haven't gotten Reactive (the main current FRP library under development) to compile yet, alas.

For some code examples, you can check out here, though I think you'll come away pretty unenlightened.  I have a suspicion that this is one of these things one has to try first-hand to get the hang of.

The reason I think FRP might be good for games is that seems to have a lot of scripting-language like features (being able to concatenate events (do this, then do this, where both events might take some length of time), coordinate simultaneous events, specify behaviour in infinitesimal terms ('move right for 3 seconds',say,  or anything that might require integration)).

Quote
As for memoization in Haskell: good question, I don't know. I trust you have read this here?
No, for some reason.  Cheers  :D
Logged
Pages: 1 2 3 [4]
Print
Jump to:  

Theme orange-lt created by panic