[gameprogrammer] Re: gameprogrammer Digest V6 #67

  • From: Erica Zarchin <toddjasp@xxxxxxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Mon, 31 Aug 2009 05:28:20 -0700 (PDT)

Hey guys,
 
     I have a bunch of Game Programming books, and I'm just curious if anyone 
would like them. I don't want to donate them becuase I figure they'll probably 
just end up getting recycled. This seems as good a place as any to give them 
away. All I ask is for the cost in shipping (payable by PayPal). 
 
I have something like 3 or 4 books.
 
1 - Game Programming in JAVA 2
2 - Game Programming in Delphi 7
3 - Game Development in C#
4 - Game Development in VB.Net
 
They're all within about 4-5 years old... the C# one is probably 2 years old 
and the VB.Net one is like 3 years old. I forget who makes them, but they're 
all from different publishers, etc. 
 
 
Anyway, shoot me an e-mail. I've kind of moved on from the thought of being a 
computer game programmer. Just don't have the time, and my career choices have 
changed.
 
Please e-mail me at this address:
 
JaspersT@xxxxxxxxxxxxxxxx
 
 
Thanks,
 
Todd
 


--- On Mon, 8/31/09, FreeLists Mailing List Manager <ecartis@xxxxxxxxxxxxx> 
wrote:


From: FreeLists Mailing List Manager <ecartis@xxxxxxxxxxxxx>
Subject: gameprogrammer Digest V6 #67
To: "gameprogrammer digest users" <ecartis@xxxxxxxxxxxxx>
Date: Monday, August 31, 2009, 1:08 AM


gameprogrammer Digest    Sun, 30 Aug 2009    Volume: 06  Issue: 067

In This Issue:
        [gameprogrammer] Re: WaitFOrMultipleObjects on Linux?
        [gameprogrammer] Re: Let's play... Name That Algorithm! :)

----------------------------------------------------------------------

From: =?gb2312?B?zMbOqg==?= <twpig2003@xxxxxxxxxxx>
Subject: [gameprogrammer] Re: WaitFOrMultipleObjects on Linux?
Date: Sun, 30 Aug 2009 06:37:54 +0000


Hi, buddy:

I want to say some words premature:

i think we can use pthread_cond_signal to notify the event
And maybe we should lock it with phread_mutex_lock & pthread_mutex_unlock
and it maybe better to arrange pthread_cond_t and pthread_mutex_t, i mean, a 
struct(you can fill something else you want, e.g. for ResetEvent)

You can read the super book(I haven't its book or pdf now)
unix network programming volume 2(or maybe volume 1?)
there is some sample code in it.

And maybe you can read the source code of ACE(it did some wrapping work to 
cross platforms)






    pthread_cond_t eventList[4];
    pthread_mutex_t hMutex[4];
    


#include "SignaledEvent.h"
#include "RakAssert.h"

SignaledEvent::SignaledEvent()
{
    numEvents=0;
}
SignaledEvent::~SignaledEvent()
{
    CloseEvents();
}

void SignaledEvent::InitEvents(int numberOfEvents)
{
    numEvents=numberOfEvents;
    RakAssert(numberOfEvents<4);
    for (int i=0; i < numEvents; i++)
    {
#ifdef _WIN32
        eventList[i]=CreateEvent(0, true, false, 0);
#else
        pthread_mutex_init(&hMutex[i],NULL);
        pthread_cond_init(&eventList[i], NULL);
#endif
    }
}

void SignaledEvent::CloseEvents(void)
{
    for (int i=0; i < numEvents; i++)
    {
#ifdef _WIN32
        CloseHandle(eventList[i]);
#else
        pthread_cond_destroy(&eventList[i]);
        pthread_mutex_destroy(&hMutex[i]);
#endif
    }
    numEvents=0;
}

void SignaledEvent::ResetEvent(int index)
{
#ifdef _WIN32
    ::ResetEvent(eventList[index]);
#else
    ???
    // I think we can ignore it if we needn't manully reset the event to 
initial state.
#endif
}

void SignaledEvent::SetEvent(int index)
{
#ifdef _WIN32
    ::SetEvent(eventList[index]);
#else
    ???
    pthread_mutex_lock(&hMutex[i]);
    pthread_cond_signal(&eventList[index]);
    pthread_mutex_unlock(&hMutex[i]);
#endif
}

void SignaledEvent::ResetEvents(void)
{
    for (int i=0; i < numEvents; i++)
    {
#ifdef _WIN32
        ::ResetEvent(eventList[i]);
#else
        ???
        // I think we can ignore it if we needn't manully reset the event to 
initial state.
#endif
    }
}

void SignaledEvent::WaitOnEvents(int timeoutMs)
{
#ifdef _WIN32
    WaitForMultipleObjects(
        2,
        eventList,
        false,
        timeoutMs);
#else
    ???
    pthread_mutex_lock(&hMutex[i]);
    pthread_cond_wait( &eventList[i], &hMutex[i] );
    pthread_mutex_unlock(&hMutex[i]);
#endif
}



Thanks!



> Date: Sat, 29 Aug 2009 11:31:52 -0700
> From: gameprogrammer@xxxxxxxxxx
> To: gameprogrammer@xxxxxxxxxxxxx
> Subject: [gameprogrammer] WaitFOrMultipleObjects on Linux?
> 
> Anyone know how to fill this out? I put my guesses in, with ??? when I 
> didn't know
> 
>     pthread_cond_t eventList[4];
>     pthread_mutex_t hMutex[4];
> 
> #include "SignaledEvent.h"
> #include "RakAssert.h"
> 
> SignaledEvent::SignaledEvent()
> {
>     numEvents=0;
> }
> SignaledEvent::~SignaledEvent()
> {
>     CloseEvents();
> }
> 
> void SignaledEvent::InitEvents(int numberOfEvents)
> {
>     numEvents=numberOfEvents;
>     RakAssert(numberOfEvents<4);
>     for (int i=0; i < numEvents; i++)
>     {
> #ifdef _WIN32
>         eventList[i]=CreateEvent(0, true, false, 0);
> #else
>         pthread_cond_init(&eventList[i], NULL);
> #endif
>     }
> }
> 
> void SignaledEvent::CloseEvents(void)
> {
>     for (int i=0; i < numEvents; i++)
>     {
> #ifdef _WIN32
>         CloseHandle(eventList[i]);
> #else
>         pthread_cond_destroy(&eventList[i]);
>         pthread_mutex_destroy(&eventList[i]);
> #endif
>     }
>     numEvents=0;
> }
> 
> void SignaledEvent::ResetEvent(int index)
> {
> #ifdef _WIN32
>     ::ResetEvent(eventList[index]);
> #else
>     ???
> #endif
> }
> 
> void SignaledEvent::SetEvent(int index)
> {
> #ifdef _WIN32
>     ::SetEvent(eventList[index]);
> #else
>     ???
> #endif
> }
> 
> void SignaledEvent::ResetEvents(void)
> {
>     for (int i=0; i < numEvents; i++)
>     {
> #ifdef _WIN32
>         ::ResetEvent(eventList[i]);
> #else
>         ???
> #endif
>     }
> }
> 
> void SignaledEvent::WaitOnEvents(int timeoutMs)
> {
> #ifdef _WIN32
>     WaitForMultipleObjects(
>         2,
>         eventList,
>         false,
>         timeoutMs);
> #else
>     ???
>     pthread_cond_wait( &eventList[i], &hMutex[i] );
> #endif
> }
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 

_________________________________________________________________
约会说不清地方?来试试微软地图最新msn互动功能!
http://ditu.live.com/?form=TL&swm=1


------------------------------

From: "Mike Gillissie" <Niyoto@xxxxxxxxxx>
Subject: [gameprogrammer] Re: Let's play... Name That Algorithm! :)
Date: Sun, 30 Aug 2009 06:04:26 -0400

Hi Kevin,

I greatly appreciate, and will definitely take you up on that offer - I 
tried porting my method into C++, but I don't have enough experience in C to 
know how to fine-tune the code, or even the compiler/linker if that's an 
option. I'll put together maybe a straight ASCII file full of 1s and 0s, one 
line per row in the adjacency table. It'll probably be Monday evening before 
I can get it together, though...

-Mike

----- Original Message ----- 
From: "Kevin Jenkins" <gameprogrammer@xxxxxxxxxx>
To: <gameprogrammer@xxxxxxxxxxxxx>
Sent: Saturday, August 29, 2009 2:51 PM
Subject: [gameprogrammer] Re: Let's play... Name That Algorithm! :)


> If you give me a file with your input set, I'll write a C function that 
> will do it in less than 1 second.
>
> Mike Gillissie wrote:
>> Hey folks,
>>
>> Just an unsolicited follow-up - after trying a lot of different 
>> approaches, I ended up sticking with the recursive model I had already, 
>> but worked in Bob's momoization concept.
>>
>> Warning - I might go a little long on this one, so read only if you're 
>> curious, bored, masochistic or find humour in the way I attempt to 
>> explain what passes for "thinking" in my world. ;)
>>
>> My main concern - even with mid-range input quantities (say, 3000 units) 
>> my function executes at least 10s of billions of times (I never bothered 
>> going long int to get an actual count). This means that everything I do 
>> in this function can have a drastic effect on performance - even using 
>> non-synchronized collections costs too many cycles.
>>
>> So, as my way of caching results, I perform a pre-check on the adjacency 
>> table, determining which rows of bools are subsets of others (or are 
>> identical, meaning they're compatible with the same sets of other units). 
>> Essentialy I determine which unit compatibility sets are subsets of 
>> others, and store this information in an array - unit index, subset-of 
>> index, delta (number of values that are different) and dependancy.
>>
>> Quick note - in the following example, 1 represents an incompatibility. 
>> Thus 0 represents compatibility.
>>
>> 1)01110 (incompatible with 2, 3, 4)
>> 2)10011 (incompatible with 1, 4, 5)
>> 3)10001 etc...
>> 4)11001
>> 5)01110
>>
>> In the above, I find that 1 and 5 are equal, and 3 is a subset of 4 with 
>> a delta of 1 (representing unit 2 which is compatible with 4 but not with 
>> 3).
>>
>> Since 1 and 5 are identical, I need only calculate for Unit 1. I can then 
>> take all of the resulting combinations for Unit 1 and replace the 1 with 
>> a 5.
>>
>> Since 3 is a subset of 4, I calculate for Unit 3 first (which has LESS 
>> incompatibilities than Unit 4), and then simply perform the same "search 
>> and replace" to create the combinations for Unit 4, only I exclude any 
>> that contain the "Delta" element (in this case, Unit 2).
>>
>> The same subset approach would be done to calculate Unit 2, since Unit 3 
>> is also a subset of 2.
>>
>> As Bob suggests, the success of this approach depends strongly on the 
>> make up of the data itself - there are always going to be situations 
>> where you just don't have enough subsets to justify the overhead of 
>> searching for them. But in the data set I'm currently working on, my 
>> execution time (which had previously gone from 3.6 hours to just over 1 
>> hour) dropped to 4-8 seconds. And this can surely be fine-tuned further.
>>
>> A further look at the problem told me that, while some compatibility sets 
>> will just not have any subsets to exploit, I could always measure the 
>> Similarity between two sets. In the above, Unit 1 and Unit 2 have a 
>> similarity of 1 (representing their shared compatibility with Unit 4). So 
>> if I was to create a "virtual" compatibility set containing Unit 4, it 
>> would become a subset of both Unit 1 and Unit 2, meaning I would only 
>> have to recursively calculate that combination once, and then use the 
>> above-approach for both Units 1 and 2. The challenge here is in finding 
>> the optimal grouping that minimizes the number of recursive calls without 
>> overpaying in overhead cycles.
>>
>> It's definitely an interesting problem for me... :)
>> -Mike
>>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
> 



------------------------------

End of gameprogrammer Digest V6 #67
***********************************

Other related posts:

  • » [gameprogrammer] Re: gameprogrammer Digest V6 #67 - Erica Zarchin