Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Excellent article on turn-based game loops  (Read 1187 times)
0 Members and 1 Guest are viewing this topic.
Online BurntPizza

« JGO Bitwise Duke »


Medals: 289
Exp: 5 years



« Posted 2014-08-03 16:41:39 »

http://journal.stuffwithstuff.com/2014/07/15/a-turn-based-game-loop/

Written by the same guy who did http://gameprogrammingpatterns.com/, it's worth a read even if you aren't developing a turn based game, you might pick up how various problems are thought about and solved regardless of genre.
Even has interactive demos!

via reddit, more discussion there
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2014-08-03 17:45:03 »

Cool article, thanks.

Offline ags1

JGO Wizard


Medals: 75
Projects: 3
Exp: 5 years


Make code not war!


« Reply #2 - Posted 2014-08-03 20:27:14 »

Quote
The game engine should be strictly separated from the user interface.

Monsters and player-controlled characters should be treated uniformly.

That sums up exactly what I am doing with my Fog game (although it is not turn based).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2014-08-04 08:36:42 »

Most of you know I'm a design-patterns-consider-harmful kinda person.  Now this author's design-patterns page is pretty good, but this is WTF.

Why on earth would one implement an action as a command-pattern?  Oh yeah because all of your problems must be broken into into a fixed set of cookie-cutter solutions.

WTF:
1  
2  
3  
4  
5  
6  
abstract class Action {
  Actor _actor;
  Game _game;
  Queue<Action> _actions;
  GameResult _gameResult;
  bool _consumesEnergy;

Every "action" not only stores the actor executing it, but also the game it's running in?  Because obviously an actor can be running in many game instances at the same time with shared state?  WTF?  And a queue?  And it's result?  Why is does even store the actor?  Oh yeah, because there are only two ways to manually dispatch a method call:  command and visitor patterns.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2014-08-04 08:42:44 »

Well, the author is nuts anyway... need scripting in your game? Write a language, parser, compiler, linker, VM, bridge to interface with native code, etc etc.

http://www.java-gaming.org/topics/gameprogrammingpatterns-com-is-finished/32890/view.html




It seems to trigger an identical response from you, too Smiley

Anyone that's been around here for awhile should know I'm a "patterns concerned harmful" kinda guy.
Most of you know I'm a design-patterns-consider-harmful kinda person.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2014-08-04 10:05:26 »

I don't know the names of most of the patterns anyway Smiley I think I know what a visitor pattern and a flyweight are supposed to achieve.
Still, his design for a roguelike engine is a perfectly sound basis.

Cas Smiley

Offline Roquen
« Reply #6 - Posted 2014-08-04 12:44:11 »

An action doesn't need a reference to the acting entity if it's passed in.  Likewise an action doesn't need a reference to the game as the entity knows that information.
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2014-08-04 13:55:49 »

Indeed, you'd normally just pass them in as parameters to the perform() method.

Cas Smiley

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2014-08-05 08:25:30 »

Most of you know I'm a design-patterns-consider-harmful kinda person.  Now this author's design-patterns page is pretty good, but this is WTF.

Why on earth would one implement an action as a command-pattern?  Oh yeah because all of your problems must be broken into into a fixed set of cookie-cutter solutions.
Last time I wrote a roguelike, I found having actions as command-pattern hugely simplified the AI and GUI, since I could generate all valid actions, then just push that list to the UI (for humans) or AI (for NPCs) to make the actual decision of which to use.

Patterns tend to be overdone and overly formalised, but I think you're throwing the baby out with the bathwater here.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Roquen
« Reply #9 - Posted 2014-08-05 09:55:27 »

Not from my viewpoint.  The author's claiming is he focusing on the architecture rather than getting things done.  Fine.  From an architecture standpoint why is an action coupled with a specific invocation of that action?  This adds complexity and is counter to the "best practices" war cry of decoupling of state and behavior.   There are situations were this is useful, but there's no rationale provided.  An example might be if you want to be able to undo action(s).  Ignoring the roguelike part this, doing it this way means fatter data and spawning an instance of an action each time one is performed.  Whereas a decoupled version requires exactly one instance per concrete action over the lifetime of the game (or zero in some cases if you're using java 8 ).

Quote
..., I found having actions as command-pattern hugely simplified the AI and GUI, since I could generate all valid actions, then just push that list to the UI (for humans) or AI (for NPCs) to make the actual decision of which to use.
A manual dispatch designed for the actions of the game is what I'm arguing...gives you all the good parts and avoids the bad.

On other things.  What's with this 'alternate' action thing?  What purpose does it serve?  None as presented.  It might if there was some common preconditions code but there's no hint of that.  Even with preconditions I wouldn't do it that way, but that another story.  Again (not important in a roguelike) spawning useless instances.  The invoked action can automatically invoke the (appropriate) alternate automatically when needed.  Also the author is seemly promoting the invoke method choosing the alternate..in some cases that makes sense in others it reduces flexibility.  Take the move example (probably the most important for a roguelike).  I'd argue it vastly superior for move to query what it's attempting to move into for what happens in that case.  Otherwise all special cases of move are in move's implementation and not with the thing in question.  Here's some snippets from move:

WTF: either the actor has already moved or it hasn't.  Otherwise seems reasonable to live in 'move'.  Probably the only other thing you might what is add if for non-hostile for talk/store action.
1  
2  
3  
4  
5  
    // See if there is an actor there.
    final target = game.stage.actorAt(pos);
    if (target != null && target != actor) {
      return alternate(new AttackAction(target));
    }

For everything else it breaks down into two independent things:
1) Either we can move to the tile this action or not.
2) Something is triggered by the (attempted) move or not.

The current mess looks like this (massive fail):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
    // See if it's a door.
    var tile = game.stage[pos].type;
    if (tile.opensTo != null) {
      return alternate(new OpenDoorAction(pos));
    }

    // See if we can walk there.
    if (!actor.canOccupy(pos)) {
      return fail('{1} hit[s] the ${tile.name}.', actor);
    }

    actor.pos = pos;

    // See if the hero stepped on anything interesting.
    if (actor is Hero) {
      for (var item in game.stage.itemsAt(pos)) {
        log('{1} [are|is] standing on {2}.', actor, item);
      }
    }

    return succeed();




Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!