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

Archived

This topic is now archived and is closed to further replies.

gimp

Coding help with bitfields?

9 posts in this topic

Currently to store my bits for the packet data I''m using defines to set individual bits. Like this: #define NET_MOVE_FORWARD 1 #define NET_MOVE_BACKWARDS 2 #define NET_MOVE_STRAFELEFT 4 #define NET_MOVE_STRAFERIGHT 8 #define NET_MOVE_JUMPJETS 16 DataStream[0] = NET_MOVE_BACKWARDS Big question is, whats the easiest way of reading out that bit again? The only way I can come up with is to start stepping though the data one bit at a time until I get to the bit I want, starting at the highest bit and subtracting values from the byte until I hit 0. Seems messy, is there a better way, something simple like: if (DataStream[0] = NET_MOVE_BACKWARDS) Humm... Why can''t I address bit like elements in an array? I can''t program in assembler BTW Many thanks Chris
0

Share this post


Link to post
Share on other sites
you could try:

if (DataStream[0] & NET_MOVE_BACKWARDS)

...that should work
I usually use the ''&''- AND bitwise operator - when I want
to find whether a bit is on or off.
Hope that helps
0

Share this post


Link to post
Share on other sites
Excellent!

I''ll give it a try, it was exactly the kind of direct testing I was looking for. Thanks...
0

Share this post


Link to post
Share on other sites
You can also combine more than one command into that varible.

MOVE_UP 1
MOVE_DOWN 2
MOVE_LEFT 4
MOVE_RIGHT 8
MOVE_FIRE 16

myMove = MOVE_UP / MOVE_FIRE

Now I am moving up and firing at the same time.
0

Share this post


Link to post
Share on other sites
Here are a few #defines that I find useful:

#define SetBit(b,c) ((c) / (b))
#define ClearBit(b,c) ((c) ^ (b))
#define TestBit(b,c) (((c) & (b) == 0))

To use it:

...
#define NET_MOVE_FORWARD 1
#define NET_MOVE_BACKWARDS 2
#define NET_MOVE_STRAFELEFT 4
#define NET_MOVE_STRAFERIGHT 8
#define NET_MOVE_JUMPJETS 16

if( TestBit(DataStream[0],NET_MOVE_FORWARD)
{
//do something
}


Just my $.02 worth

David "Dak Lozar" Loeser

P.S.
I would also suggest using hex values for your defines
it makes it somewhat easier to read
eg.

#define NET_MOVE_FORWARD 0x01
#define NET_MOVE_BACKWARDS 0x02
#define NET_MOVE_STRAFELEFT 0x04
#define NET_MOVE_STRAFERIGHT 0x08
#define NET_MOVE_JUMPJETS 0x10
#define NET_MOVE_HIDE 0x20


Edited by - Dak Lozar on 4/26/00 11:18:11 PM
0

Share this post


Link to post
Share on other sites
You''ll want to create a bitfield datatype class, it makes it easier to manage and manipulate bitfields. Also consider using another form of constants other than #defines, perhaps enumerations or consts, it''s safer imho. Good Luck!

-ddn
0

Share this post


Link to post
Share on other sites
quote:
Original post by Dak Lozar

Here are a few #defines that I find useful:

#define SetBit(b,c) ((c) / (b))
#define ClearBit(b,c) ((c) ^ (b))
#define TestBit(b,c) (((c) & (b) == 0))



Should that not be /= and ^=, respectively?
Warning: using ^= to clear a bit is a little hit-and-miss. If that bit was already cleared, you will end up setting it! This means you'd really have to check your bit beforehand before clearing it, eg:

if (!TestBit(variable, SOME_BIT))
ClearBit(variable, SOME_BIT);

Which seems like too much hassle to me. Try changing ClearBit above to ToggleBit (a more accurate description) and use this instead:

#define ClearBit(b,c) ((b) &= (~c))

Which should preserve every bit in the original variable except the bit(s) you are trying to clear, with no conditional checking on your part.

Edited by - Kylotan on 4/27/00 5:44:06 AM
0

Share this post


Link to post
Share on other sites
Kylotan,
Your correct... thanks for catching that.
Here's how it should look

#define SetBit(b,c) ((c) / (b))
#define ToggleBit(b,c) ((c) ^ (b))
#define ClearBit(b,c) ((b) &= (~c))
#define TestBit(b,c) (((c) & (b) == 0))


When I tried to add the = (equal) sign to the macro as you suggested, I got complaints from VC++.... other than that these macros should work of course you could always create a bit class that held these as member funcs.

Btw, the point the Anon poster made about enums is valid.

I am a long time "C" programmer (about 14 years) that has been coding C++ for about 3 years. So, breaking my #define habbit is difficult. As of late I have been limiting them to utility macros as explained in the March 2000 issue of C/C++ Users Journal page 27.




David "Dak Lozar" Loeser

Edited by - Dak Lozar on 4/27/00 7:58:27 PM
0

Share this post


Link to post
Share on other sites
Thank''s so very much everyone, I feel armed with heaps of cool techniques now to get this done.

From these cool macro''s through to the minimal bit data types I''m inventing as I go along.

Thanks anon poster too, I didn''t really the read the enum bit until Dak drew my attention to it (I''ve never used enum before) but I suppose it would be a pretty cool way of doing it.

I still don''t get the comment about bitfield datatype classes. Right now I''m just using an array of char''s and looking at something called a byte datatype. Is there something better I should use?

BTW : I really starting to get the hang of the lockstep method that brad pickering mentioned a while back. You should see the kind of things you can do with it. I can hardly wait to play my own game! I''ve just realised that with lockstep you can safely do shooting collision testing on you own machine and just post the results out if you actually hit. -very cool-

chris
0

Share this post


Link to post
Share on other sites