FastPointer

Blitz3D Forums/Blitz3D Programming/FastPointer

Yue(Posted 2012) [#1]
I want someone to help me with an example application to the lib enteder FastPointer.

As I understand Blitz3D runs in a single process, but I think I can be wrong and you can do two tasks at once with this lib, am I right? and would welcome a more focused example of what is a video game, sorry for my ignorance.


Yasha(Posted 2012) [#2]
you can do two tasks at once with this lib, am I right?


Yes, but it is difficult. There is an example in "Example_ThreadsUse.bb" and "Example_ThreadsUse2.bb". You should be completely confident in the use of function pointers, before you try to use threading.

However, there are some problems:

- the library does not provide synchronisation. This makes communicating between threads quite difficult. For this reason threads should not share resources.

- you cannot use graphics commands from any thread other than the main one.

- you need to ensure that a thread's work is completed before you use the result. This means that if you have e.g. several threads processing vertex positions for an animation system, the main thread needs to wait for all of the child threads to complete before it can apply the changes and render the mesh, or you will get a corrupted mess on screen.

For 95% of tasks, you don't need to use threading in Blitz3D anyway, and you can use "fake threading" for most of the rest. Threading with FastPointer is difficult, and there is no safe way to go about it - I would advise not to bother, unless you really, really need it (as opposed to just wanting to try).

Either way, do learn about, and use, the FastPointer function pointers. Those are very useful indeed for more than just threading.


Yue(Posted 2012) [#3]
Ok, I greatly appreciate your help in clarifying the issue. My concern is this and sorry for the ignorance on the subject.

Well, I can do with this in two threads, one equivalent to an animation of "loading" in the other thread and resource loading.

On one occasion try to do it but the image of the animation was static while on load, so I want to know if with this dual wires do.

Greetings.


Yasha(Posted 2012) [#4]
That's certainly a use for multithreading.

However, if all you want to do is have an animation play while something loads (and don't care about whether you actually do it with multithreading or not), take a look at this archives sample: Threading

It fakes multitasking by splitting the work of loading the file into small enough steps to fit between animation updates.


If you really want to use FastPointer, I guess this looks helpful: render in thread

Couldn't tell you whether it's any good, haven't looked at it myself yet.


Yue(Posted 2012) [#5]
oh! Tnaks fried =)


Yue(Posted 2012) [#6]
Well, I tried both methods yet because I liked the ease of fastpointer because in the first loading a texture always great progress bar starts charging after a second or two, you may not yet understand well the method.

The fastpointer is great because of beginning with the animation and put it in some way in the background resource loading.

This is only a test model lack better.

Similarly I am very happy because you always learn something from Blitz3D especially Yasha who is always willing to help.



[bbcode]
Graphics 800, 600, 32, False

Local img% = LoadAnimImage("Yue.jpg", 128,128,0,4)
Global imgdraw%

Function Cargarimagen( imagen%=0 )

If imagen% = 0
imagen% = LoadImage ("Dibujo.bmp")
Else
imgdraw% = True
End If


DrawImage imagen%, 0, 0

Return imagen%
End Function
ThreadFunctionPointer = FunctionPointer()
Goto skip
Cargarimagen()
.skip

Thread = CreateThread (ThreadFunctionPointer, im)

Repeat

;RenderWorld


If imgdraw% = False
DrawImage img%, 0,0,Rand(0,3)
Else
FreeImage img%
End If

Flip
Until KeyDown(1)
[/bbcode]

Now the question is: I'm working alone on dual core processors?

Last edited 2012