• 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

Allocation, Initialization & Deallocation of Objects

0 posts in this topic

I'm building a reflection system, I've got the parser, I've got the reflection system to turn the parsed data into objects in game, I've got binary reading/writing for serialization ( that can even withstand a few code changes so it's not rigid and doesn't require rebuilding binaries every time the code is changed ) I've got a fair bit of stuff going in it. Now I come to what is probably the most important aspect to me as the programmer who's going to use it ( other important aspects such as the syntax for the language being simple enough for designers/artists)

(Note: For the time being let's think architecture design, leave any DO or DO NOT, allocate in constructor/initialization function as a secondary tip, not the main article because I don't really want to go into that argument here. I'm not even going to say where I side on that. And I don't want such considerations to be an interference in the design of my memory/initialization solution, I just want the best solution either or. So truce? )

What I want to explore is how to allocate the memory for objects, delete them effectively, as well as handle the initialization of the data for the object. There are a few ways of doing this and I'm more than happy to code a couple out to see if they're feasible before I stick with one. The techniques I know of are:

(A): Using specific reflection struct, as input to constructor for object

struct ReflectionData {
class ReflectionUser {
ReflectionUser( ReflectionData& );

Created with:

template <typename Type, typename Reflect>
void Constructor( void* object, void* reflect ) {
if( reflect ) {
// inline constructor - reflection
new (object) Type( *(Reflect*)reflect );
} else {
// inline constructor - no reflection
new (object) Type;

This would pretty much be using new/delete with the factory handling the delete.

(B): By initializing the data members directly from reflection, no parsing of reflection struct. This has the advantage that the reflection system can be used for live edit without any live-edit specific support for standard types. Types that have custom behaviours, such as entities that have components will need a general purpose function for live edit to be created, but it would be just 1 function for all components.

class MyClass {
int x, y, z;

// Call Init from the factory once the object has had it's members loaded to load in textures etc
void Init();

template <typename T>
void Construct( void* object, DataObject&amp; data ) {
new (object) T;
for( data ) {
// Get the field name
// find the field in T
// Get the Type of the field
// Use the type to construct the object
// Paraphased code:
Construct< field_type >( object + field_offset, data[field_index] );

void MyClass::Init() {
// Load texture or something.

One thing I can do with this techique to load texture resources is that any object that has resources, owns a texture object, and when the texture object is created via the reflection system, it's constructor adds it to a list of textures that need to be loaded to a resource manager. Simple enough.

That's the two ways I know of doing this, if you have any others I would like to hear them because I don't feel comfortable continuing when I only have 2 options to select from; I find myself ignorant of other possible techniques.

As to Deletion:

Using new/delete means I can use the new keyword in any construction of objects and the deletion of objects is handled by whatever class owns them. This is simple enough. It is possible to delete the objects through the reflection manager, with something such as:


// Definition for a field
struct Field {
size_t offset;
bool is_pointer;

struct Type {
Field *fields;

template <typename T>
void Destroy( void * object ) {
// Get the object Type
Type* t = get type from database
for all fields
if field is pointer
Destroy< field type >( object + field offset )

free( object )

Any one who of any other / or best use strategies to achieve this?


I am a bit slow but I figured out I can use a template as well as template specialization to handle any objects that require a resolve step, such as asset loading, as most objects created are not going to need to load assets and any assets that are loaded will be from a pretty specific set of items, such as:
- Textures
- Audio
So all I need to do is create a templated Resource type

template <typename T>
class Resource {
Resource( T&amp; data );
shared_ptr<T> resource;

And then partially specialize the reflection system's constructor function:


template <typename T>
void TypeHandler<Resource<T>> (void *object, Data&amp; data ) {
// Construct type T from Data
T tobj;
for ( data as field ) {
tobj[field] = data[field];

// Now create the resource from that T obj value
new (object) Resource<T>( data );

And in the constructor for resource:

template <typename T> Resource<T>::Resource( T&amp; data ) {
resource = manager.Find( data );

As well as setting up some templates for the different resource managers etc, this should pretty much achieve what I'm after as far as designing the 'resolve' step in my project. Will still keep checking to see if anyone has any examples or different methods they've used in the past. Edited by Kyall

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