View previous topic - View next topic |
Author |
Message |
XMark Guitar playin' black mage
Joined: 30 May 2002 Posts: 870 Location: New Westminster, BC, Canada
|
Posted: Wed Oct 02, 2002 8:55 pm Post subject: working on collision detection... |
[quote] |
|
I've jumped back into work on the ARC Legacy Gold engine, and currently I'm trying to get collision detection to work. The way I'm doing it is over the 128x128 map is another map which shows where you can walk and where you can't. I figured the best way to do it is for only 1 bit of data to be used for each tile (0 = not wall, 1 = wall) but there doesn't seem to be a binary data type in C++. I've googled bit manipulation and found some really confusing algorithms to isolate individual bits using bitwise AND and OR operations, but I was wondering, is there some kind of standard C or C++ library to hold a really big chunk of bits in an array-like structure?
EDIT:
Oh, also, my research led me to making a struct to hold variables in individual bits like
typedef struct {
unsigned char switch1:1;
unsigned char switch2:1;
} switches;
Is there anyway to make a switch array within the struct? (so I could access it like switches.switch[4] = 1)
Setting it like unsigned char switch[8]:1; doesn't seem to work. _________________ Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
|
|
Back to top |
|
|
Rainer Deyke Demon Hunter
Joined: 05 Jun 2002 Posts: 672
|
Posted: Wed Oct 02, 2002 10:07 pm Post subject: |
[quote] |
|
Since, using 'unsigned char', you're only looking at 16K, I'm not sure why you even care. However, the template class 'std::bitset' in the C++ standard library might be what you're looking for.
|
|
Back to top |
|
|
XMark Guitar playin' black mage
Joined: 30 May 2002 Posts: 870 Location: New Westminster, BC, Canada
|
Posted: Wed Oct 02, 2002 10:52 pm Post subject: |
[quote] |
|
yeah, I know it's a bit overkill but I have a history of extremely poor and messy coding style which I'm trying to eradicate using any means possible :) Thanks for the pointer.
EDIT:
heh, on second thought, maybe I'll just stick with chars. There's some wasted memory space but it leaves it open in case I want to extend the collision detection to include different movement types (like going slow through a swamp or something) _________________ Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
|
|
Back to top |
|
|
Mandrake elementry school minded asshole
Joined: 28 May 2002 Posts: 1341 Location: GNARR!
|
Posted: Thu Oct 03, 2002 12:52 pm Post subject: |
[quote] |
|
boolean values are always a nicety, and a standard...not sure if they are only 1 bit apeice though.
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Thu Oct 03, 2002 6:11 pm Post subject: |
[quote] |
|
Never, it wouldn't even be faster. The following piece of code:
printf("%d byte(s)", sizeof bool);
outputs:
1 byte(s)
|
|
Back to top |
|
|
mandrakeooo Guest
|
Posted: Thu Oct 03, 2002 6:14 pm Post subject: |
[quote] |
|
well that's pointless. why the hell would a bool need to be a byte? seems like a lot of wasted space to me.
|
|
Back to top |
|
|
Rainer Deyke Demon Hunter
Joined: 05 Jun 2002 Posts: 672
|
Posted: Thu Oct 03, 2002 6:43 pm Post subject: |
[quote] |
|
'bool' must be at least one byte so that its address can be taken. (Pointers can only point to whole bytes.) Moreover, some compiler actually have 'sizeof(bool) > sizeof(char)'. They justify it by calling it a speed optimization.
Last edited by Rainer Deyke on Fri Oct 04, 2002 12:33 am; edited 1 time in total
|
|
Back to top |
|
|
janus Mage
Joined: 29 Jun 2002 Posts: 464 Location: Issaquah, WA
|
Posted: Thu Oct 03, 2002 9:04 pm Post subject: |
[quote] |
|
yeah, some compilers use unsigned ints for booleans. Visual Basic uses a signed integer. >:) It's actually quite useful in that case.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Thu Oct 10, 2002 6:49 pm Post subject: |
[quote] |
|
Actually if you wan't the best of both worlds use vector<bool> whats confusing about it is that it's really not a vector of bools, every element takes only one bit but if you later decide that you need extra bits to carry extra information you just change from bool to char and voila 8x memusage but lot's of extra bits to put data in.
isn't STL a wonderful thing? _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
Hard Rock Sick of Being A Fairy Princess Yet?
Joined: 22 Jun 2002 Posts: 14
|
Posted: Thu Oct 10, 2002 10:45 pm Post subject: |
[quote] |
|
Quote: | Oh, also, my research led me to making a struct to hold variables in individual bits like
typedef struct {
unsigned char switch1:1;
unsigned char switch2:1;
} switches;
Is there anyway to make a switch array within the struct? (so I could access it like switches.switch[4] = 1)
Setting it like unsigned char switch[8]:1; doesn't seem to work |
Thats c++ right? well i code in c and know no c++ but id take a guess that unsigned char switch1[8];1 does not work becuase theres 8 settings that have to be set(right, for what the 3d time?, i have no knowlege of c++, so im guessing ;1 works like = 1), try this:
unsigned char switch1[8]{1,1,1,1,1,1,1,1}(that should work in c, or maybe i screwed something up in that code in dunno)
or to make things easier, just dont set it in the struct and create a sub somewhere that does it for you using a for loop.
Then again im an idiot so feel free to ignore my post.( ive never even tested the {} thing) _________________ Hard Rock
http://starsdev.cjb.net
|
|
Back to top |
|
|
Mandrake elementry school minded asshole
Joined: 28 May 2002 Posts: 1341 Location: GNARR!
|
Posted: Tue Oct 15, 2002 2:04 pm Post subject: |
[quote] |
|
hmm, that vector bool thing is nifty....i'm loving STL more and more i learn about it...only wish MSVC++ was up to date on the STL standards....there is so much cool stuff you can't even dream of accessing in VC++...which sucks.
|
|
Back to top |
|
|
janus Mage
Joined: 29 Jun 2002 Posts: 464 Location: Issaquah, WA
|
Posted: Wed Oct 16, 2002 8:28 am Post subject: |
[quote] |
|
VC7 is supposed to have excellent STL support.
|
|
Back to top |
|
|
Mandrake elementry school minded asshole
Joined: 28 May 2002 Posts: 1341 Location: GNARR!
|
Posted: Wed Oct 16, 2002 12:29 pm Post subject: |
[quote] |
|
right, but i don't have the money to cough up dough for VC 7 or .net dev studio or whatever that package is called now. Purely a GCC man as of late.
|
|
Back to top |
|
|
white_door Icemonkey
Joined: 30 May 2002 Posts: 243 Location: New Zealand
|
Posted: Fri Oct 18, 2002 8:07 pm Post subject: stl |
[quote] |
|
well I have MSVS .NET (that's version 7) and while it has support for most of STL, it doesn't cover everything. like using custom function objects for sorting .. and other stuff. And it doesn't have any of the sgi extentions to STL either.
the hash_map is really quite cool :p
|
|
Back to top |
|
|
XMark Guitar playin' black mage
Joined: 30 May 2002 Posts: 870 Location: New Westminster, BC, Canada
|
Posted: Fri Oct 18, 2002 8:33 pm Post subject: |
[quote] |
|
Is anyone else getting a popup asking for username and password for fury.rpgsource.net when they view this thread? _________________ Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
|
|
Back to top |
|
|