• 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.
  • entries
    94
  • comments
    271
  • views
    150267

Refactoring with components

Sign in to follow this  
Followers 0
evanofsky

848 views

I've been refactoring my engine with the component-entity model, and things are turning out quite nicely. The one problem I always had with components was the way inter-component dependencies were handled. In the article I linked (one of the classics on the subject), the author says his components originally referenced each other through a component manager, but eventually they allowed components to store pointers to each other for performance reasons. In my mind, that's way too many concrete dependencies.

So I'm rolling my own data binding system. Instead of directly accessing a component's data from another component, I'm having both components store a copy of the properties they need. So if the physics component wants to overwrite the position and orientation of the model component, I don't have to do this inside the physics component:

this.ModelComponentReference.WorldTransform = blah;
Instead, the physics component and model component have separate transforms. These act like input/output ports for each component. When constructing an entity, I bind the two "ports" together. I can also use multiple inputs for one output by combining them together with a transformation function. I can also bind actions (which is basically like event handling).

Here's a good example of the power of this system. Let's say I have a working player entity, and I want to have it play footstep sounds when he's walking. I already have a PositionComponent and a PlayerStateComponent (with an enum of states like Idle, Running, Jumping...).

Let's create a TimerComponent that has a few properties like Enabled, Interval, and Repeats, and an action (or event) that fires when the timer expires. First we would set a proper interval and enable repeating. Then we could create a binding for the Enabled state, which would set Enabled to true whenever the player's state is "Running". In my implementation, this is accomplished with a closure.

Then we can create a SoundComponent that's set up with our footstep sounds, and whose 3D position is bound to our player's position. We could then bind the TimerComponent's firing event to the SoundComponent's "Play" method. Mission accomplished.

Bear in mind that this system is still untested and I'm still in the middle of refactoring, but so far it's looking good. Here's a screenshot of my player factory code to give you an idea of how I'm doing this:

fdPNl.jpg


So there you go. It's not perfect, but I think it's going to work. The idea, at least, is sound. I'll post later about the details of my binding system, which is still a matter of some contention. I'm trying to keep things clean while avoiding reflection at all costs.

Mirrored on my blog

0
Sign in to follow this  
Followers 0


2 Comments


This is interesting. I imagine it results in a pretty decoupled system. How do the components get updated each frame, are you holding them in some array or list?

It'd be interesting to see a comparison of performance between the older engine and the refactored one.
2

Share this comment


Link to comment
Yeah, I just have a list of entities, each of which has a list of components. So all the components in entity one or updated, then entity two, etc. I think the data binding will slow the engine down a bit, but luckily I'm not doing too much processor-intensive work.

But I do think this pattern lends itself pretty well to multi-threading. You could pretty easily split it up so one thread updated all the components of a certain type or something. I'll have to give it a shot some time.
0

Share this comment


Link to comment

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