Pages: 1
Author Topic: sprite_add/sound_add/background_add from OTHER sources than files (raw/data).  (43,830 Views)
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Posted on: May 22, 2014, 05:18:04 AM
This might sound crazy, but as I am paving the way for my external resource engine, where I would use my created functions to extract a particular segment from a file.....

Currently you can use sound_add and sprite_add,
background_add, etc. but they all add from files.......
So in this case it means I would have to have my engine read bytes from a file and write them to another and invoke the *_add functions to read the newly written file.

In order to avoid 2 unnecessary steps such as writing and reading, what if there was a function to add sprite, sound, background from variable.  :D  As Harri suggested from data / raw, so it can take from content of a variable or buffer.

Here is an example:

file=".\data\graphics.res";
file2=".\data\cache\intro.png";
file_bin_open(file,0);
file_bin_seek(file,16000);
repeat (1024)
{
data += chr((file_bin_read_byte(file)));
}
file_bin_close(file);

file_bin_open(file2,1);
repeat (size)
{
i++;
character=string_byte_at(data,i);
file_bin_write_byte(file2,character);
}
file_bin_close(file2);

sprite=sprite_add(file2,1,0,0,0,0);
obj_0.sprite_index=sprite;


This is just a quickly made draft, inside a create event,
will read 1024 bytes from graphics.res starting at position 16000 and store into variable data.  Then it will write a file with the  contents of data. 

As you can see here I am invoking the sprite add which will read the newly  created file.

What if there was a way to simply say:

sprite=sprite_add_from_string(data,1,0,0,0,0);
sprite=sprite_add_from_raw(data,1,0,0,0,0)

This way I could simply remove all code involved for writing ! All that would be needed is a file binary read storing it in data and fetching whatver is in data to sprite add.

Effectively loading resources directly to memory.

This would save disk space and speed things up.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: May 22, 2014, 07:28:48 AM
Good idea. Worth adding.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #2 Posted on: May 22, 2014, 07:49:41 AM

Guess I should rename the topic to add
also
sound_add_from_string
background_add_from_string
or any *_add function apply to string and not just add from files.


sound_add_from_raw
video_add_from_raw
background_add_from_raw
sprite_add_from_raw

So the concept is simple......
Instead of having the function *_add (which already reads the file and stores it in memory), why not have the function read the data directly from a string variable. from raw data from a buffer/memory. For a large game with lot of resources it would save disk writes and another read, speed up
loading of resources as well.
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #3 Posted on: May 22, 2014, 09:05:41 AM
I don't like the implications of it relying on the standard implementation of string though, and I'm sure Josh will concur.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #4 Posted on: May 22, 2014, 09:52:06 AM
Sadly we really have only one type people tend to use - variant (or var). Asking a person to actually declare types for specific functions don't seem to be the best option. I don't think there is a problem with storing it in string though. If it is just a char array, the it's the same as byte array and we should be fine. We maybe just shouldn't call it _from_string, but _from_data or _from_raw or something like that.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #5 Posted on: May 22, 2014, 04:44:30 PM
Quote from: TheExDeus on May 22, 2014, 09:52:06 AM
Sadly we really have only one type people tend to use - variant (or var). Asking a person to actually declare types for specific functions don't seem to be the best option. I don't think there is a problem with storing it in string though. If it is just a char array, the it's the same as byte array and we should be fine. We maybe just shouldn't call it _from_string, but _from_data or _from_raw or something like that.

Good point and idea Harri, yes add from buffer or add from raw.

What about add from buffer ? though I heard buffer is not quite done in ENIGMA yet....

Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #6 Posted on: May 22, 2014, 08:58:14 PM
Buffers work, just not with floats, and alignment may not work because well, their shit makes no sense, their buffer implementation is a fucking trainwreck.
Offline (Unknown gender) Darkstar2

Member
Joined: Jan 2014
Posts: 1,238
View profile
Reply #7 Posted on: June 25, 2014, 09:17:18 PM
BTW, any follow-up on this proposal ? I think for large game developers learning to use efficient, dynamic resource handling is a positive step, keeping the IDE fast and tidy.  Those not wanting to use individual files and pack file formats reading only a range of bytes from a file directly to memory.

Pages: 1