2005-08-05 09:15:41 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#if defined(__AMIGA__) || defined(__MORPHOS__)
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) { return NULL; }
|
|
|
|
void* OTTDJoinThread(OTTDThread* t) { return NULL; }
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
void OTTDExitThread() { NOT_REACHED(); };
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
|
|
|
|
#define INCL_DOS
|
|
|
|
#include <os2.h>
|
|
|
|
#include <process.h>
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
struct OTTDThread {
|
2005-08-05 09:15:41 +00:00
|
|
|
TID thread;
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThreadFunc func;
|
2005-08-05 11:53:48 +00:00
|
|
|
void* arg;
|
|
|
|
void* ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
};
|
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
static void Proxy(void* arg)
|
|
|
|
{
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* t = arg;
|
2005-08-05 11:53:48 +00:00
|
|
|
t->ret = t->func(t->arg);
|
|
|
|
}
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* t = malloc(sizeof(*t));
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
t->func = function;
|
|
|
|
t->arg = arg;
|
|
|
|
t->thread = _beginthread(Proxy, NULL, 32768, t);
|
2005-08-05 09:15:41 +00:00
|
|
|
if (t->thread != -1) {
|
|
|
|
return t;
|
|
|
|
} else {
|
|
|
|
free(t);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
void* OTTDJoinThread(OTTDThread* t)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2005-08-05 11:53:48 +00:00
|
|
|
void* ret;
|
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
DosWaitThread(&t->thread, DCWW_WAIT);
|
2005-08-05 11:53:48 +00:00
|
|
|
ret = t->ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
free(t);
|
2005-08-05 11:53:48 +00:00
|
|
|
return ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
}
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
void OTTDExitThread(void)
|
|
|
|
{
|
|
|
|
_endthread();
|
|
|
|
}
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
#elif defined(UNIX)
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
struct OTTDThread {
|
2005-08-05 09:15:41 +00:00
|
|
|
pthread_t thread;
|
|
|
|
};
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* t = malloc(sizeof(*t));
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
if (pthread_create(&t->thread, NULL, function, arg) == 0) {
|
2005-08-05 09:15:41 +00:00
|
|
|
return t;
|
|
|
|
} else {
|
|
|
|
free(t);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
void* OTTDJoinThread(OTTDThread* t)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2005-08-05 11:53:48 +00:00
|
|
|
void* ret;
|
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
2005-08-05 09:15:41 +00:00
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
pthread_join(t->thread, &ret);
|
2005-08-05 09:15:41 +00:00
|
|
|
free(t);
|
2005-08-05 11:53:48 +00:00
|
|
|
return ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
}
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
void OTTDExitThread(void)
|
|
|
|
{
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
#elif defined(WIN32)
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
struct OTTDThread {
|
2005-08-05 09:15:41 +00:00
|
|
|
HANDLE thread;
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThreadFunc func;
|
2005-08-05 11:53:48 +00:00
|
|
|
void* arg;
|
|
|
|
void* ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
};
|
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
static DWORD WINAPI Proxy(LPVOID arg)
|
|
|
|
{
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* t = arg;
|
2005-08-05 11:53:48 +00:00
|
|
|
t->ret = t->func(t->arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2006-08-19 09:23:48 +00:00
|
|
|
OTTDThread* t = malloc(sizeof(*t));
|
2005-08-05 09:15:41 +00:00
|
|
|
DWORD dwThreadId;
|
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
|
|
|
|
2005-08-05 11:53:48 +00:00
|
|
|
t->func = function;
|
|
|
|
t->arg = arg;
|
2005-08-05 20:18:08 +00:00
|
|
|
t->thread = CreateThread(NULL, 0, Proxy, t, 0, &dwThreadId);
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
if (t->thread != NULL) {
|
|
|
|
return t;
|
|
|
|
} else {
|
|
|
|
free(t);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 09:23:48 +00:00
|
|
|
void* OTTDJoinThread(OTTDThread* t)
|
2005-08-05 09:15:41 +00:00
|
|
|
{
|
2005-08-05 11:53:48 +00:00
|
|
|
void* ret;
|
|
|
|
|
|
|
|
if (t == NULL) return NULL;
|
2005-08-05 09:15:41 +00:00
|
|
|
|
|
|
|
WaitForSingleObject(t->thread, INFINITE);
|
|
|
|
CloseHandle(t->thread);
|
2005-08-05 11:53:48 +00:00
|
|
|
ret = t->ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
free(t);
|
2005-08-05 11:53:48 +00:00
|
|
|
return ret;
|
2005-08-05 09:15:41 +00:00
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
void OTTDExitThread(void)
|
|
|
|
{
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
2005-08-05 09:15:41 +00:00
|
|
|
#endif
|