• 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
gretty

Using Preprocessor Directives to achieve a form of specialisation

1 post in this topic

Hello

[i]The following is an attempt to challenge myself to achieve specialisation by using Preprocessor Directives and is not a serious project. The aim is to attempt to see if its possible so its best to avoid asking why I am doing this and instead see if what I am attempting to do is possible out of fun and interest.[/i]

I have an idea to achieve a form of specialisation(well mainly abstraction and virtualisation) in pure C[i](* See Note at end)[/i]. The idea comes slightly out of necessity but mostly for fun and I dont think I will pursue this in a real project but I am interested to see if it can be sucessfully implemented.

Example of how I use Preprocessor Directive Macro Functions to achieve 'abstract' functions:

[CODE]
// This is 4dm not pure C. 4dm is a language very similar to C
// except it doesn't have structs, pointers & you cannot declare
// new data types. The language is used to wrtie macros for a civil engineering application.
// Language Information: http://www.12dmodel.com/downloads/documentation/12d_progm.pdf

// Global Variables //
{
Draw_Box windows[3]; // a widget that you can draw text & images to

Integer WINDOW_TEXT;
Integer WINDOW_HYPERLINK;
Integer WINDOW_IMAGE;
}

#define WRITE(str,param1) str(param1)
#define draw_generic_window(windowIndex, type) \
if (type==WINDOW_TEXT) WRITE(draw_text_window,windowIndex) \
else if (type==WINDOW_HYPERLINK) WRITE(draw_hyperlink_window,windowIndex) \
else if (type==WINDOW_IMAGE) WRITE(draw_image_window,windowIndex)

void draw_text_window(Integer windowIndex)
{
print("draw_text_window():", windowIndex);
}

void draw_hyperlink_window(Integer windowIndex)
{
print("draw_hyperlink_window():", windowIndex);
}

void draw_image_window(Integer windowIndex)
{
print("draw_image_window():", windowIndex);
}

void main()
{
windows[1] = Create_draw_box(100,100,0);
windows[2] = Create_draw_box(100,100,0);
windows[3] = Create_draw_box(100,100,0);

draw_generic_window(1, WINDOW_TEXT);
draw_generic_window(2, WINDOW_HYPERLINK);
draw_generic_window(3, WINDOW_IMAGE);

/* At compile time the above should be converted to the following
draw_text_window(1);
draw_hyperlink_window(2);
draw_image_window(3);*/
}
[/CODE]

[b]My Problem: [/b]Whilst I can sucessfully use "virtual" functions, ie, use draw_generic_window() it requires me to always pass the type of the window as a parameter in the function. Can you think of a way where I wont have to pass the windows' type and the program will figure it out on its own? I hope this makes sence, if you look at the next example you will see where my problem is.

[CODE]
// More globals
{
Integer WINDOW_NUM = 0;
Integer windowTypes[3];
}

void create_window(Integer type)
{
if (WINDOW_NUM >= 3)
return;

WINDOW_NUM++;
windows[WINDOW_NUM] = Create_draw_box(100,100,0);
windowTypes[WINDOW_NUM] = type;
}

void draw_all_windows()
{
// arrays start at 1 in 4dm. 3 is the number of Draw_Boxes(windows) I have
for (Integer i=1; i<=3; i++)
{
// PROBLEM HERE: when I call the following macro windowTypes[i] will always be 0
// Any ideas?
draw_generic_window(i, windowTypes[i]);
}
}

void main()
{
create_window(1);
create_window(2);
create_window(2);

while (1) {
draw_all_windows();
}
}
[/CODE]

[b]Any ideas how I can overcome this next issue?[/b]

Note: This is actually programmed in a language very similar to C called 4dm. Its the same except it has no pointers, structs and you cannot define new data types. But it does have pass by reference and preprocessor instructions. So that may provide a bit more of a reason why I am trying to achieve specialisation in this way. [url="http://www.12dmodel.com/downloads/documentation/12d_progm.pdf"]http://www.12dmodel....n/12d_progm.pdf[/url]

Another of my reasons is that I want to avoid the following method that also achieves specialisation but its inefficient:

[CODE]
void draw_all_windows()
{
// Every draw loop I am checking what type the window is which can be inefficient and make the program not scalable
// So you can see how coming up with a preprocessor solution would be efficient aswell as a little elegant.

// arrays start at 1 in 4dm. 3 is the number of Draw_Boxes(windows) I have
for (Integer i=1; i<=3; i++)
{
switch (windowTypes[i])
{
case WINDOW_TEXT:
{
draw_text_windiw(i);
}
break;
case WINDOW_IMAGE:
{
draw_image_windiw(i);
}
break;
....
}
}
}
[/CODE] Edited by gretty
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