0 registered members (),
1,094
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Name of the assigned function and model
[Re: Ch40zzC0d3r]
#462376
09/24/16 14:34
09/24/16 14:34
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
memcpy(buff, ent, sizeof(ENTITY)) You can't overwrite its CLINK struct or the bunch of pointers an entity struct contains without getting in troubles.
|
|
|
Re: Name of the assigned function and model
[Re: txesmi]
#462377
09/24/16 14:52
09/24/16 14:52
|
Joined: Oct 2011
Posts: 1,082 Germany
Ch40zzC0d3r
Serious User
|
Serious User
Joined: Oct 2011
Posts: 1,082
Germany
|
memcpy(buff, ent, sizeof(ENTITY)) You can't overwrite its CLINK struct or the bunch of pointers an entity struct contains without getting in troubles. Good point Thats why we gotta preserve some values and keep them after loading from the file. Shouldnt be too much values you have to preserve.
Last edited by Ch40zzC0d3r; 09/24/16 14:53.
|
|
|
Re: Name of the assigned function and model
[Re: Ch40zzC0d3r]
#462381
09/25/16 16:28
09/25/16 16:28
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I did another workaround of the needs I think you could have.
#include <acknex.h>
STRING *str = "";
TEXT *txtLevels =
{
string = ( "level00", "level01" );
}
TEXT *txtConfigs =
{
string = (
" -pal palette.pcx -az 0 -el 60 -sunrgb 58 58 58 -ambrgb 19 19 19 -fog1 100 100 100 -fog2 19 39 100 -fog3 100 19 19 -noportals -hiprec -litmapsonly -writelog -mesh -mergeacross -terralit -tesselate -close -solidsky -nodetail -quiet -supsam -threads 4 -gamma 2.25 -phongangle 120 -lmambient 50 -sizeshaded 236 -litres 0.37 -litcomp 0.20 -litmax 255 -litscale 0.68 -radsubdiv 64 -radbounce 3 -bound 56000 -fat 64 48 8 -narrow 32 32 0"
" -pal palette.pcx -az 0 -el 60 -sunrgb 58 58 58 -ambrgb 19 19 19 -fog1 100 100 100 -fog2 19 39 100 -fog3 100 19 19 -noportals -hiprec -litmapsonly -writelog -mesh -mergeacross -terralit -tesselate -close -solidsky -nodetail -quiet -supsam -threads 4 -gamma 2.25 -phongangle 120 -lmambient 50 -sizeshaded 236 -litres 0.37 -litcomp 0.20 -litmax 255 -litscale 0.68 -radsubdiv 64 -radbounce 3 -bound 56000 -fat 64 48 8 -narrow 32 32 0"
);
}
typedef struct
{
char buffer[6000];
char *chr;
long size;
} ENT_BUFFER;
ENT_BUFFER entBuffer;
void entBuffer_startup ()
{
entBuffer.chr = entBuffer.buffer;
entBuffer.size = 0;
}
void entBufferLevel ( STRING *_str )
{
long _size = str_len ( _str );
memcpy ( entBuffer.chr, _str->chars, _size );
entBuffer.chr += _size;
*entBuffer.chr = 13;
entBuffer.chr ++;
*entBuffer.chr = 10;
entBuffer.chr ++;
entBuffer.size += _size + 2;
}
void entBufferAdd ( char *_chr, long _size )
{
memcpy ( entBuffer.chr, _chr, _size );
entBuffer.chr += _size;
entBuffer.size += _size;
}
void main ()
{
wait(1);
var levelIndex = 0;
for ( ; levelIndex<txtLevels->strings; levelIndex+=1 )
{
entBufferLevel ( (txtLevels->pstring)[levelIndex] );
var entIndex = 0;
str_cpy ( str, (txtLevels->pstring)[levelIndex] );
str_cat ( str, ".$$M" );
char *entityBlock = NULL;
long size;
char *buffer0 = file_load ( str, NULL, &size );
char *buffer = buffer0;
char *bufferLast = buffer + size;
for ( ; buffer<buffer0+size; buffer++ )
{
if ( *buffer == 123 ) // {
{
var pos = str_stri ( buffer, "model" );
if ( pos )
if ( pos < 10 )
entityBlock = buffer;
}
if ( entityBlock )
{
if ( *buffer == 125 ) // }
{
long size2 = 3 + (long)buffer - (long)entityBlock;
entBufferAdd ( entityBlock, size2 );
long size3 = size;
size3 -= (long)buffer - (long)buffer0;
memcpy ( entityBlock, buffer+3, size3 );
size -= size2;
buffer = entityBlock - 1;
entityBlock = NULL;
}
}
}
file_save ( str, buffer0, size );
file_load ( NULL, buffer0, &size );
str_cat ( str, (txtConfigs->pstring)[levelIndex] );
exec_wait ( "wwmp2wmb.exe", str );
}
file_save ( "level_entities.txt", entBuffer.buffer, entBuffer.size );
sys_exit ( NULL );
}
It recompiles a list of levels listed on a TEXT struct but with no models and creates a single txt file with the description of the models taken from the $$M files generated by WED. This way you could load empty levels and create just the models that are active instead or removing unactive ones. Salud!
|
|
|
Re: Name of the assigned function and model
[Re: 3run]
#462385
09/26/16 05:17
09/26/16 05:17
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
I am glad of helping I forgot to warn you that this last code is not problem free. Be aware of making a backup of level files before using it on your real game. It modifies $$M files on hard disk. I will modify it in order to restore its initial state after recompiling and add some security checks. Salud!
|
|
|
Re: Name of the assigned function and model
[Re: txesmi]
#462392
09/26/16 18:53
09/26/16 18:53
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I commented all the process and renamed the variables so it is easier to follow. It now restores the level files initial state after compiling the empty levels, so there is no need for making backups of the files.
#include <acknex.h>
// -----------------------------------------------------------------------------------------------------
STRING *strFilename = NULL;
STRING *strOptions = "";
// -----------------------------------------------------------------------------------------------------
// Levels
TEXT *txtLevels =
{
string = (
"level00.$$M",
"level01.$$M"
);
}
// Compilation configurations for each level
// They can be copied from 'buildlog.txt' file created by WED compilation process
TEXT *txtConfigs =
{
string = (
" -pal palette.pcx -az 0 -el 60 -sunrgb 58 58 58 -ambrgb 19 19 19 -fog1 100 100 100 -fog2 19 39 100 -fog3 100 19 19 -noportals -hiprec -litmapsonly -writelog -mesh -mergeacross -terralit -tesselate -close -solidsky -nodetail -quiet -supsam -threads 4 -gamma 2.25 -phongangle 120 -lmambient 50 -sizeshaded 236 -litres 0.37 -litcomp 0.20 -litmax 255 -litscale 0.68 -radsubdiv 64 -radbounce 3 -bound 56000 -fat 64 48 8 -narrow 32 32 0"
" -pal palette.pcx -az 0 -el 60 -sunrgb 58 58 58 -ambrgb 19 19 19 -fog1 100 100 100 -fog2 19 39 100 -fog3 100 19 19 -noportals -hiprec -litmapsonly -writelog -mesh -mergeacross -terralit -tesselate -close -solidsky -nodetail -quiet -supsam -threads 4 -gamma 2.25 -phongangle 120 -lmambient 50 -sizeshaded 236 -litres 0.37 -litcomp 0.20 -litmax 255 -litscale 0.68 -radsubdiv 64 -radbounce 3 -bound 56000 -fat 64 48 8 -narrow 32 32 0"
);
}
// -----------------------------------------------------------------------------------------------------
// A buffer and a position and size control in order to hold all the entity related data
typedef struct
{
char buffer[6000];
char *chr;
long size;
} ENT_BUFFER;
ENT_BUFFER entBuffer;
void entBuffer_startup ()
{
entBuffer.chr = entBuffer.buffer;
entBuffer.size = 0;
}
// Add a string to the entities buffer
void entBufferAddString ( STRING *_str )
{
long _size = str_len ( _str );
memcpy ( entBuffer.chr, _str->chars, _size );
entBuffer.chr += _size;
*entBuffer.chr = 13; // [Enter]
entBuffer.chr ++;
*entBuffer.chr = 10; // Linebreak
entBuffer.chr ++;
entBuffer.size += _size + 2;
}
// Add a char buffer to the entities buffer
void entBufferAdd ( char *_chr, long _size )
{
memcpy ( entBuffer.chr, _chr, _size );
entBuffer.chr += _size;
entBuffer.size += _size;
}
// -----------------------------------------------------------------------------------------------------
void main ()
{
wait(1);
var levelIndex = 0;
// Loop through all levels
for ( ; levelIndex<txtLevels->strings; levelIndex+=1 )
{
// Get the pointer to the level name string
strFilename = (txtLevels->pstring)[levelIndex];
// Check the existence of the level file
if ( !file_exists ( strFilename ) )
{
str_cpy ( strFilename, " file not found!" );
error ( strFilename );
break;
}
// Add level name to entities buffer
entBufferAddString ( strFilename );
// A variable will contain the size of the file buffer
long sizeFile;
// Load the file into a buffer allocated by the engine
char *bufferStart = file_load ( strFilename, NULL, &sizeFile );
// Make a copy of the file buffer in order to restore the file after compiling
char *bufferBackup = sys_malloc ( sizeFile );
memcpy ( bufferBackup, bufferStart, sizeFile );
// A pointer to hold the starting byte of a detected entity
char *entityBlock = NULL;
// A variable will contain the size of the modified file buffer. It is same as the original file buffer size at the beginning
long sizeResult = sizeFile;
// A pointer to go through the buffer
char *buffer = bufferStart;
// Go through the buffer byte by byte
for ( ; buffer<bufferStart+sizeResult; buffer++ )
{
// If a description of a model has been previously detected
if ( entityBlock )
{
// If the pointed byte is a closing bracket
if ( *buffer == 125 ) // }
{
// Compute the size of the entity description block
long sizeBlock = 3 + (long)buffer - (long)entityBlock;
// Add the entity block to the entities buffer
entBufferAdd ( entityBlock, sizeBlock );
// Compute the size of the remaining buffer
long sizeRemaining = sizeResult - ( (long)buffer - (long)bufferStart );
// Move the remaining buffer to the starting byte of the entity, so the entity is completelly removed from the file buffer
memcpy ( entityBlock, buffer+3, sizeRemaining );
// Reduce the size of the file buffer by the size of the entity block
sizeResult -= sizeBlock;
// Move the buffer cheking pointer to the start of the remaining buffer, as it has been moved
buffer = entityBlock - 1;
// Remove previously saved starting byte
entityBlock = NULL;
}
}
else // If a description of a model has not been previously detected
{
// If the pointed byte is an opening bracket
if ( *buffer == 123 ) // {
{
// Look for the word 'model' into the remaining buffer
var pos = str_stri ( buffer, "model" );
// If it exists
if ( pos )
{
// If it exists near the opening bracket
if ( pos < 10 )
{
// Save the the actual byte as the starting byte of the description of a model
entityBlock = buffer;
}
}
else // If it does not exists
{
// There is no reason to continue looking into the buffer
// Break the loop
break;
}
}
}
}
// Save the modified buffer, with no models, in order to compile the empty level
file_save ( strFilename, bufferStart, sizeResult );
// Build the configuration for compiling process
str_cpy ( strOptions, strFilename );
str_cat ( strOptions, (txtConfigs->pstring)[levelIndex] );
// Compile the level
exec_wait ( "wwmp2wmb.exe", strOptions );
// Restore the level file to its initial state
file_save ( strFilename, bufferBackup, sizeFile );
// Remove the level buffer
file_load ( NULL, bufferStart, &sizeFile );
// Remove the level buffer copy
sys_free ( bufferBackup );
}
// If everything went fine
if ( levelIndex == txtLevels->strings )
{
// Save the entities buffer
file_save ( "level_entities.txt", entBuffer.buffer, entBuffer.size );
}
// Exit the program ;)
sys_exit ( NULL );
}
Have fun!
|
|
|
Re: Name of the assigned function and model
[Re: txesmi]
#462605
10/14/16 13:49
10/14/16 13:49
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Incase someone wants a simple save to text solution (for whatever reason like modding or such) I am just gonna drop these functions here (replace tmp_str with the string you are going to use to save/load values/info). I used it for a first description and than on next line the value. But you can also do several values on 1 line if you read them out with e.g. str_parse. Note that as a delimiter (/to seperate the lines) I use a \n / enter-thingy . When you change it just dont forget to change both functions.
//For loading/reading (go to next line and read)
function read_line(var handle) {
str_cpy(tmp_str, ""); //reset previous read lines
file_str_readto(handle, tmp_str, "\n", 10000); //read next line
str_trim(tmp_str); //remove spaces from value
str_trunc(tmp_str, 1); //remove \n (/remove delimiter)
}
//For saving/writing (write blank to next line)
function skip_line(var handle) {
file_asc_write(handle, 13); //new line
file_asc_write(handle, 10);
}
So for saving you do file_open_write and use something like file_str_write(handle, "Entity file:"); to write a line and call skip_line(handle); to skip a line (/go to next line for writing), than e.g. file_str_write(handle, str_for_entfile(NULL, ent)); . After you are finished dont forget to close the file. For reading you do file_open_read and call read_line(handle); when you want to go the next line AND read that line of the file. So say the first line is a description and the second line has the value, call read_line(handle); twice. Than read the string on that line by doing something like ent.x = str_to_num(tmp_str); . Again dont forget to close the file. For saving/loading multiple entities loop through them by e.g. using ent_next or your entity pointer array if you have one.
|
|
|
|