1

Topic: use tick function in teeworld code

hey guys

i need a function that can repeat statements infinite,i guess i should use GameTick or other time variables  to do this but when  i use gametick in loops (while or for) this causes lag or game crash! i saw this function(tick) in lua file that is used in (n-client)
but i dont know how can i do this in teeworld source code.

2

Re: use tick function in teeworld code

Don't use while and for for that purpose. Put your code in some methods from your components (names are explicit) such as OnReset, OnRender, OnMessage...

Not Luck, Just Magic.

3 (edited by 2013-01-18 00:52:02)

Re: use tick function in teeworld code

veryyy helpful post
tnx alot

i defined a global variable , i want value of this variable increases every second,i tried many ways such as (if LocalTime()%x == y)var++

but it didnt work,and the variable increased irregularly!
can you help me in this case?!

4

Re: use tick function in teeworld code

Look in the code how to get the time. Look in components/hud.cpp for how the ingame clock is rendered for example smile

Not Luck, Just Magic.

5

Re: use tick function in teeworld code

tnx
i saw that file and i got how to do that
but still i have 1 problem,i use OnRender() method for repeat , speed of this method is very fast(its logical),and value of the variable does not increase just every sec !

6

Re: use tick function in teeworld code

For Serverfiles, like Character, player, gamecontext... you can use

if(!(Server()->Tick()%Server()->TickSpeed()))
{}

now you can search for sth wit "Tickspeed" in client and copy it

#yemDX is a known troll

7

Re: use tick function in teeworld code

i want use function in client file,is any method that to be run every (x)seconds?
is it possible to make a method like OnRender but execution speed of it be lower?!!

8

Re: use tick function in teeworld code

No.

Not Luck, Just Magic.

9

Re: use tick function in teeworld code

Does Teeworlds use Mutex for multithreading?!

10

Re: use tick function in teeworld code

Dune wrote:

No.

Not Luck, Just Magic.

11 (edited by TinToWw 2013-01-18 21:16:06)

Re: use tick function in teeworld code

so what does teewolrds use for  multithreading?!
SDL?

12

Re: use tick function in teeworld code

TinToWw wrote:

so what does teewolrds use for  multithreading?!
SDL?

No multithreading.

Not Luck, Just Magic.

13

Re: use tick function in teeworld code

Dune wrote:
TinToWw wrote:

so what does teewolrds use for  multithreading?!
SDL?

No multithreading.

This is new to me.

Concerning the question: Teeworlds uses POSIX-Threads and the Windows-API
Atm also SDL semaphores are needed for Mac OS X, because unnamed semaphores aren't supported on OS X.
However you found the thread stuff in src/base/system.h/.c and atomics int src/base/tl/threading.h (NOTE: don't relay on the documentation in this header)

14

Re: use tick function in teeworld code

Uuuh, did I miss something? Sorry then.

Not Luck, Just Magic.

15 (edited by TinToWw 2013-01-20 01:52:37)

Re: use tick function in teeworld code

tnx BeaR
last week i read a document about multithreading,in one of part it said Windows does not support the pthreads standard natively!
now i use SDL for multithreading and it works fine wink

Where "fire" and "hook " events are defined?!

16

Re: use tick function in teeworld code

So let's clear this up a little:
Teeworlds DOES use threads - not much however.
They can be used via the thread_* functions of system.h, no further SDL dependencies necessary.

Where are threads used in Teeworlds:

  • graphics, with asyncrender enabled

  • sound loading, with threadsoundloading enabled (I would really recommend this, it's speeding up the startup heavily

  • master server lookup

The latter two are done via the engine's CEngineJob interface, which I would recommend looking into, nicely done by matricks. smile

17 (edited by 2013-01-20 19:25:06)

Re: use tick function in teeworld code

tnx heinrich5991

what about mutex ?? is it in teeworlds src too?!

how can i get localplayer mouse position(in client)?!

18

Re: use tick function in teeworld code

Why not directly asking for the code for your bot?

Not Luck, Just Magic.