#include <acknex.h>
#include <default.c>
#include <windows.h>
//
//
//---------------------------------------------------------------------------------------
//
HANDLE Thread_ONE; DWORD worker_ONE(void *ignored); short* worker_ONE_data=NULL;
HANDLE Thread_TWO; DWORD worker_TWO(void *ignored); short* worker_TWO_data=NULL;
ENTITY* worker_TWO_entity;
long close_threads = 0; //global thread terminator
//
//
//---------------------------------------------------------------------------------------
//
#define HeightMap "height_map.dta"
#define HeightMapWidth 16384
#define HeightMapHeight 12288
#define TerrainDimensions 128
//
//---------------------------------------------------------------------------------------
//
//
void main()
{
wait(1); level_load(NULL); wait(1); diag("\n\n\n");
draw_textmode("Times",0,32,100); warn_level = 3; on_esc = NULL;
//------------------------------------------------------------------------------------
//
// Thread_ONE = CreateThread(NULL, 0x00, worker_ONE, 0x00, 0x00, 0x00);
// Thread_TWO = CreateThread(NULL, 0x00, worker_TWO, 0x00, 0x00, 0x00);
//
//
while(!key_esc)
{
wait(1);
}
//
close_threads = 1; // game over, time to kill the threads
while(worker_ONE_data != Thread_ONE) wait(1); //wait until thread ONE terminated
while(worker_TWO_data != Thread_TWO) wait(1); //wait until thread TWO terminated
//
//
//
//------------------------------------------------------------------------------------
if(key_shift) exec("notepad.exe", "acklog.txt");
sys_exit(0);
}
//
//
//
//---------------------------------------------------------------------------------------
//
// The below file-retrieval code "largely" conjectural, as the files design not finalized
// and this code has no real error-checking and it aint optimised by a long shot...
DWORD worker_ONE(void *ignored)
{ //NOTE: for the record, THIS code is limited to 1.2g image files, not the API's
var last_frame = 0; //place to remember last frame I did processing on.
short* data_block = NULL; //pointer to data block supplied via worker_ONE_data
long file=0, y, x_off,y_off, count, file_ptr_lo; //various local workspaces
long width=sizeof(short)*TerrainDimensions; //various local workspaces
Sleep(0x1000); //snooze for a bit. Let everything else get running.
//
while(!close_threads) //loop until global terminate is triggers
{
if((worker_ONE_data)&&(total_frames>last_frame))
{
data_block = worker_ONE_data; data_block[1]=1; //set status active
x_off=(long)data_block[1]; y_off=(long)data_block[2]; //retrieve offsets
if((x_off<0)||(y_off<0)) { error("poo! Illegal Offsets!"); break; }
SetFilePointer(file, file_ptr_lo, 0x00, 0x00);
file_ptr_lo = x_off + (y_off * HeightMapWidth);
file = CreateFile(HeightMap, 0x80000000, 0x00, 0x00, 0x03, 0x00, 0x00);
if(!file) { error("Oh crap! Cant find HeightMap!"); break; }
//start retrieving data
for(y=0; y<TerrainDimensions; y++)
{
ReadFile(file, &(data_block[y*TerrainDimensions+1]), width, &count, 0x00);
if(count!=width) { error("Dammit! Hit end-of-file!"); break; }
file_ptr_lo = x_off + ((y+y_off) * HeightMapWidth);
SetFilePointer(file, file_ptr_lo, 0x00, 0x00);
}
CloseHandle(file); file=NULL;
data_block[0] = 0; data_block = NULL; //set status to complete.
worker_ONE_data = NULL; //disconnect from data source/s
last_frame=total_frames; //remember to not process more THIS frame
}
//
Sleep(100); //snooze for 100 milliseconds (for now, will drop to 10 or 1 or zero)
}
worker_ONE_data = Thread_ONE; //signal that this thread is terminated
}
//
//
//---------------------------------------------------------------------------------------
//
// The below vertex-adjustment code "largely" conjectural, as this code has only been
// tested to COMPILE state. MUCH testing will be needed to verify thread-safety...
DWORD worker_TWO(void *ignored)
{
var last_frame = 0; //place to remember last frame I did processing on.
short* data_block = NULL; //pointer to data block supplied via worker_TWO_data
ENTITY* entity = NULL; //pointer to data block supplied via worker_TWO_entity
var x, y; //various local workspaces
CONTACT c; D3DVERTEX* verts; //various local workspaces
Sleep(0x1000); //snooze for a bit. Let everything else get running.
//
while(!close_threads) //loop until global terminate is triggers
{
if((worker_TWO_data)&&(worker_TWO_entity)&&(total_frames>last_frame))
{
data_block = worker_TWO_data; data_block[1]=1; //set status active
entity = worker_TWO_entity; //retrieve pointer to affected terrain entity
ent_getvertex(entity,c,1); ent_setvertex(entity,c,1); verts = c.v;
//start modifying terrain heights
for(y=0; y<TerrainDimensions; y++) for(x=0; x<TerrainDimensions; x++)
verts.y = data_block[y*TerrainDimensions+x+1];
data_block[0] = 0; data_block = NULL; //set status to complete.
worker_TWO_data = worker_TWO_entity = NULL; //disconnect from data source/s
last_frame=total_frames; //remember to not process more THIS frame
}
//
Sleep(100); //snooze for 100 milliseconds (for now, will drop to 10 or 1 or zero)
}
worker_TWO_data = Thread_TWO; //signal that this thread is terminated
}