• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
NevermoreDCE

How to handle timing of events

3 posts in this topic

I'm working on a data-driven 2D turn-based combat game (which will eventually be a component of a 4X game) inspired by classics like Space Empires II/III and I'm making pretty good progress, but I've run into a problem with the timing of execution of certain events. I know it's probably making my life a lot harder than it needs to be, but I'm working in WPF currently as I'm trying to avoid involving any frameworks like XNA or Unity (since they seem like they'd be overkill for what I'm trying to accomplish, a crutch that would let me blindly ignore important systems and processes I want to understand, and would take me away from my original reason for starting this project which is learning new technologies, methodologies, practices, and patterns that could apply to my Day Job as a C# applications developer).

In my game, a Ship object is given orders (ShipOrder object), and as part of the Start-Of-Turn process all of the orders on a ship are executed (method on the Ship loops through all orders calling their ExecuteOrder method). These orders include movement (e.g. MoveToLocation), which I built first, and firing weapons (e.g. FireAtTargetShip) which I built later. Each order, when executed, raises an event and the main program subscribes to these events and resolves them.

The problem I'm facing is due to a decision I made when building the movement orders: I wanted the movement of the ship icon on the screen to hesitate between squares (for now, each ship can move 3 squares per turn), so I found and implemented a delayed execution service mechanism (basically, a static method that gets passed an action plus parameters for the action, then creates a timer that will trigger an event to execute the action, thus creating a delay in the action). Link to my code where the delayed execution is called. Unfortunately (and what I think is the crux of my problem), the (delayed) action includes not only moving the image of the ship on the screen, but changing the actual position of the ship internally in the game state.

The issue I can't figure out how to resolve is the fact that while the delayed timer is off doing its thing, the other orders continue to get executed, so I can't figure out how to force the FireAtTargetShip orders to wait until movement is complete before they trigger off, so they're going off almost instantly so their range calculations are done from the ship's position at the beginning of the turn, not where it is when it finishes movement.

I almost need a stack-like or pipeline-like system to pass the results of the ExecuteOrder methods into, where I can add things to the process and resolve them only when the previous item is completely resolved.

So my question is, is it best at this point to implement a pipeline system (e.g ExecuteOrder adds an item to an ordered array, resolution of an order raises an event that triggers the beginning of the next item in the array, etc) and will a pipeline resolve my problem, or is there either an easier/better way to accomplish this (or some fundamental flaw in what I'm attempting to do that will bite me later on)?
0

Share this post


Link to post
Share on other sites

I know some turn-based games solve this by having a MovePhaseAtStartOfTurn followed by a AttackPhaseAtStartOfTurn. You can sometimes see this reflected by the animations in commercially available games. Basically, you just need a sync on starting the attack phase to completion of movement. Technically, you could even just add a wait equal to the maximum animation/movement time required if you don't have the ability to sync. That's hacky since it might break if you add a longer animation/movement later, so definitely better to sync if possible.

0

Share this post


Link to post
Share on other sites
You need only a small modification to your Order class, most likely.

Just stop executing Orders if one returns a code that it is going to take time. Keep trying to drain the Order queue for the unit each frame until it's empty and the game state can advance. The Order object can then be in charge of knowing if it has to wait for an animation to complete or some wait timer to complete. There's not necessarily any reason to have one queue of Orders feed another queue.
0

Share this post


Link to post
Share on other sites

You need only a small modification to your Order class, most likely.

Just stop executing Orders if one returns a code that it is going to take time. Keep trying to drain the Order queue for the unit each frame until it's empty and the game state can advance. The Order object can then be in charge of knowing if it has to wait for an animation to complete or some wait timer to complete. There's not necessarily any reason to have one queue of Orders feed another queue.

There are a few limitations to keep in mind with this approach. In multi-threading execution of orders, "wait for me" status becomes a lock and that's an awful lot of locks. Order of execution becomes important (unit A moves and fires at B, unit B fires at A. What distance was B at when firing at A?). And you always cause a delay equal to the longest dependency chain's animations, which can be really bad if you allow move-fire-move orders.

 

None of this is to say the approach should be avoided as long as you understand the limitations. If you do not have actions interacting with one another and are single-threaded, it probably works fine. While I think having a move phase where you process movements and requeue other orders is easier, other programmers will certainly disagree. That's the art aspect of programming.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0