1 (edited by Rastislav Kiss 2017-01-18 19:50:10)

normally I searching on Google before asking question somewhere, hovever in this case I haven't any idea what to do or search. My problem is following:
I am developing minecraft for the blinds as I noticed few times before. For begin, I selected surface of size 200*200*200 blocks, what gives 8000000 blocks. That is okay, game is relative fast, working without lags etc. Problem shows when loading map. for first versions of project, I choosed simple notation like this:
me.x;me.y;me.z;block.x;block.y;block.z;block.id;block.x;bnlock.y;block.z;block.id etc.
Yeah, it can be reduced by using for example ascii characters to reduce size, but that is not important now, problem is in time which program needs to load map.
For first, I choosed method of loading all blocks to the string, and split them with string_split. Hovever this wasn't so effective, result array has 8000000 instead of 16000000 places. I don't know why, but as I am thinking about it, is possible that there were some programming mistakes, but that isn't important, after it I choosed my own method to read string with map character by character, find separators and enter values to the three dimensional array, which is used as a main world matrix.
Code was simple, like read_until function from file object, there was one pointer and something like:
string string_read_until(string input, int pointer) {
string result="";
while (input[pointer]!=";") {

This is not of course original code, it has seeable out of bounds bug when implementing, but original has prevention, this is only example how code looks. It works, only small mistake was there. Loading duration was about 50 minutes, loading space 200*200*10.
I didn't know what to do. After some time, I got an idea. I overwrited my function with read_until from file object, and whole system remaked to read directly from file. I was really surprised when after this change map loaded in time about 10-20 seconds.
And that is what I don't understand, why reading from my ssd hardrive (not tested on hdd) is faster than reading from memori? Ram should to be faster if I know right, so why this is happening? I am asking also because now I am working on server, and clients take again about 50 minutes to load sended map, that's really long,I need to make it faster but don't know how to do it, only solution seems to save received map to the file and use standard loading method, but this is not explayning problem itself, also more disk usage is needed.
Thank you for help, I want to record small introduction for our Slovak and Czech blind community, so we need multiplayer mode as soon as possible.


Thumbs up


Hi Rasťa,
do you use a wait call in your while loops in the file reading functions? Or possibly, have you reserved some memory in advance for the array which receives the result of the string split? Tiny little performance precautions and tweaks like this can make a world of difference sometimes. If you were doing the above, then I would probably need to see your original attempt at this function. I think I wouldn't need anything else, just this single function should be enough.


Thumbs up


another thing is, read_until in file object is a function written in C++ and it was compiled into native code, while bgt turns your functions to byteCode which is slower

bitcoin address: 1LyQ3hziMC2DTnCtgM3V1zfuZ73P3CYT9P

Thumbs up


@Lukas: I am not using wait in this loops, but I am not reserving memory for array, I don't know how to do it in bgt. I have no code for this function yet, I removed it after starting to use file object, but I will make it again, when I will done, I can post it here.
@Visualstudio: When you talking about it, I think that it can be the problem, do you think that coding loading function to the c++ and using it as a dll can make whole process as fast as with file object?


Thumbs up


Interesting idea about coding the file loading function and accessing it through a DLL then. This is an area I can't help with yet, having no personal experience with other languages, but I would certainly be interested in seeing the results of that experiment. :-)

About not using wait calls in such kind of loops, that's definitely a good thing because you do want the CPU to run at its maximum speed for such short and computation intensive periods of time, so that's fine.

As for reserving memory, you just do array.reserve (number_of_expected_elements);
Check out the array object reference. I believe this could also help a lot, as the memory for each new entry wouldn't have to be allocated only on the actual insertion itself, which can be a bit late.


Thumbs up


Hello all,
so I returned to the coding after small pause and begun with this project. I decided to not make directly dll and its joining when I don't know what will be the result, but I decided to take basic surface from bc (blindcraft, I know that there is similar project called with the same name hovever it is in unknown phase and I created title by myself for my product, so I will call it blindcraft while there is no concrete product from someone other) and coded it in c++. It was interesting work, I am not very experienced in this language so I started with making bgt_kit for c++, for this time only basic needed classes like file. After it I made few comparisons that will possibly not surprise pro developer, but I was really amazed:

First - declaration of three dimensional array 200*200*200, bgt 4 seconds, c++ 1 second. Not very important, difference can be produced by bgt's resizing cycles which c++ do not need.

- assigning array with values (part integers), in this case array hat int type. Result: bgt 1 second, c++ 1 second.
- assigning array with values (part blocks), now array hat block value, block is class with two variables, int id and string zone. Result: bgt 4 secs, c++ between 1 and 2 secs. It is interesting, looks like c++ have faster organization in its classes, but it is still not very important, few seconds is survivable thing if did only one time.

- loading map from file, this is most interesting and most important part of this comparison, I will repeat what is program doing while loading from file:
1. Load file to string variable.
2. set pointer variable to 0 and call read_until function which will use the pointer variable to return text until given symbol. (note: by pointer is meaned int variable, not pointer as a type).
3. this read_until function is called four times in one loop to separate x, y and z position of each block + its id, loop is called until function returns blank string, that means end of the file, so end of map too. In this step all returns are converted to int and assigned to the world array.

And that is all, both languages hat the same or very similar functions and result? Bgt - estimated 55 minutes, c++ - 3 seconds!!!

Someone can find my surprise very stupid, probably it is, I knew that bgt is slower than other languages because of byte code, but I did not know that difference can be counted in hours, days or veeks if there are larger maps. I will only add that loaded data was not size 200*200*200, air is not saved with the map and this was default layout (flat world) used for testing with volume 200*200*10. So imagine that this two languages are loading full map, possible later when I add things like mountains, mines etc., time 20 it is 20 hours for bgt, 1 min for c++.

Testing was not made with something like timers or stopwatchs, I listened only for my clocks on wall, but ration between values is correct. Anyway small numbers are not important, I wrote about the main difference and there is no problem with measuring. Now I decided to remake bc in c++, It will be funny because I have no basics like audiolibraryes or some functions usable in audiogames, I must bring them from bgt, for audio I successfully compiled bass library used for example also in Eurofly, so I will look what I can do in c++, how similar can I do It to soundpool, if I have success, I will probably make it public for next beginning c++ ag developers.

Thanks for reading, hope it wasn't too boring. smile


Thumbs up