Register for your free account! | Forgot your password?

You last visited: Today at 03:01

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Release] TimeOut functions

Discussion on [Release] TimeOut functions within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old   #1
 
pintinho12's Avatar
 
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
[Release] TimeOut functions

Hello guys, i think this will be my first real contribution to the forum. By the way, it's nothing so hard to do heheh.

I've been working on my WCProject and on the Battle System that is based on Demons Source, i noticed that they have those classes implemented.
Firstly, i tried using what most sources use, DateTime and Environment.TickCount, I don't know if this class will save or spend more resources, but i don't need to rewrite Update and Reset codes all the time, and it got a lot easier to code timers with this now.

Note: This do not execute anything automatically, just stores the time.

First, you need a Unix Timestamp class, something to return Seconds and Milliseconds.
I will provide my code, if you have anything better to contribute, i will edit here.

Unix Timestamp.cs
*
Below, i have the TimeOut and TimeOutMS classes.
TimeOut hasn't been tested yet, but i am using TimeOutMS on my Meele Attack, and it's working like a boss.


I will provide commented code and examples later. ^_^
Hope it helps anyone #00

Almost forgot...
Calculations does contains this

pintinho12 is offline  
Old 03/25/2015, 01:30   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Unless I'm blind and missing something, all that code is just a fancy way of dealing with unix timestamps and has nothing to do with actually DELAYING an action.

There's no threading referenced and there's no actions.

Not saying it can't be useful but just seems like a needlessly large amount of code when it's not actually accomplishing something.
pro4never is offline  
Thanks
1 User
Old 03/25/2015, 08:52   #3
 
elite*gold: 67
Join Date: Aug 2014
Posts: 1,323
Received Thanks: 928


I wrote that a few weeks ago. Take a look
Xio. is offline  
Thanks
1 User
Old 03/25/2015, 13:59   #4
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
This code has a bit more overhead than is needed. Instead of using DateTime to get the Unix time you could use Environment.TickCount which gives you more resolution to work with (milliseconds instead of seconds). The only "issue" with using Environment.TickCount over Unix time is that every 43 or so days the tick count resets to 0.
-impulse- is offline  
Thanks
1 User
Old 03/25/2015, 14:27   #5
 
pintinho12's Avatar
 
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
This does not have anything to do with Threading.
I have an OnTimer method on my classes that will need things handled.
The point is that i can use var tm = new TimeOut(5); and check elsewhere with .ToNextTime() or .IsTimeOut()
When I get back home tonight I will check the sugestions, tho, this class works pretty fine, since i use both on my Status handlers, for shackle, fog, etc
Ty for the feedback.
pintinho12 is offline  
Old 03/25/2015, 14:37   #6
 
elite*gold: 67
Join Date: Aug 2014
Posts: 1,323
Received Thanks: 928
Quote:
Originally Posted by -impulse- View Post
This code has a bit more overhead than is needed. Instead of using DateTime to get the Unix time you could use Environment.TickCount which gives you more resolution to work with (milliseconds instead of seconds). The only "issue" with using Environment.TickCount over Unix time is that every 43 or so days the tick count resets to 0.
Every 25 days and its a 100 ns increment not a ms increment. If you need more accuracy you can use the Stopwatch class.
Xio. is offline  
Old 03/25/2015, 18:49   #7
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
Quote:
Originally Posted by Xio. View Post
Every 25 days and its a 100 ns increment not a ms increment. If you need more accuracy you can use the Stopwatch class.
1 ms.



And if you use Environment.TickCount as an unsigned number you get 49.8 days.
-impulse- is offline  
Thanks
1 User
Old 03/25/2015, 20:43   #8
 
elite*gold: 67
Join Date: Aug 2014
Posts: 1,323
Received Thanks: 928
Quote:
Originally Posted by -impulse- View Post
1 ms.



And if you use Environment.TickCount as an unsigned number you get 49.8 days.
Wow thanks, I thought Ticks is the same o_o

Xio. is offline  
Old 03/26/2015, 05:46   #9
 
pintinho12's Avatar
 
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
So, if i use that on this same function, i will save a lot of time then?
pintinho12 is offline  
Old 03/26/2015, 13:11   #10
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
Quote:
Originally Posted by pintinho12 View Post
So, if i use that on this same function, i will save a lot of time then?
Not "a lot" but that something adds up to a whole lot after a while. Yes, it's worthwhile changing your base (Unix timestamp) to the local TickCount. If you need stuff like day of the month you should use DateTime.UtcNow because it's a bit faster but for keeping stamps of seconds it's faster to use TickCount. Depends on the usage really.
-impulse- is offline  
Old 03/26/2015, 14:42   #11
 
pintinho12's Avatar
 
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
It's most used for methods that wont store more than a few minutes or hours, i believe the server wouldn't be more than a 2-3 days online without a restart, so i think that this will be great. I'll take a look at this tonight.
pintinho12 is offline  
Old 03/27/2015, 01:08   #12
 
U2_Caparzo's Avatar
 
elite*gold: 0
Join Date: Aug 2011
Posts: 314
Received Thanks: 90
I checked your project, you are trying to make it the more similar possible to the EO source, so why not keep doing it that way, it may become a really useful resource for those who are much more familiar with C# than C++

Anyways, because of the topic i'm posting this , i coded a task scheduler few months ago as well, it was supposed to handle things like remove items from floor, effects, etc... i think that it's a decent one (except that the PriorityQueue is List based and insert should be far away from O(log n) ^^)

Use example:
Code:
        public static TaskScheduler TaskScheduler;
        static void Main(string[] args)
        {
            TaskScheduler = new TaskScheduling.TaskScheduler();
            ScheduledAction<string, string> delayedAction1 = new ScheduledAction<string, string>(Write, DateTime.Now.Second.ToString(), "This action is executed in the TaskScheduler thread");
            ScheduledAction<string, string> delayedAction2 = new ScheduledAction<string, string>(Write, DateTime.Now.Second.ToString(), "This action is executed in the ThreadPool");
            delayedAction2.ExecuteInThreadPool = true;  // default = false, false to execute the action in the TaskScheduler thread, or true to execute 
                                                        // in the ThreadPool, note that if the action takes too long to finish and is not executed
                                                        // in the ThreadPool, next actions may be executed with an extra delay
            TaskScheduler.Schedule(delayedAction1, 3000);
            TaskScheduler.Schedule(delayedAction2, 5000);
            Console.WriteLine("Actions added to the TaskScheduler at second " + DateTime.Now.Second);
            delayedAction2.Await();     // Blocks the thread untill the ScheduledAction has been executed
            Console.WriteLine("\ndelayed action 2 executed at second " + DateTime.Now.Second);
            TaskScheduler.Stop();
            Exit();
        }

        static void Exit()
        {
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }

        static void Write(string value0, string value1)
        {
            Console.WriteLine("\n\t" + value1 + "\n");
            Console.WriteLine("\t\t[ThreadId=" + Thread.CurrentThread.ManagedThreadId + "] Original DateTime second: " + value0);
            Console.WriteLine("\t\t[ThreadId=" + Thread.CurrentThread.ManagedThreadId + "] Now DateTime second: " + DateTime.Now.Second);
        }
Attached Files
File Type: zip TaskSchedulerExample.zip (96.1 KB, 11 views)
U2_Caparzo is offline  
Thanks
1 User
Old 03/27/2015, 01:43   #13
 
pintinho12's Avatar
 
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
Just came back from work and got some things to do, i will do a check on this later too, thanks. xD
I think that using while and Thread.Sleep() is awful, so those things might be useful to me.
pintinho12 is offline  
Old 03/27/2015, 13:41   #14


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
Instead of Thread.Sleep(1) in a loop you can use WaitOne with a time parameter.
KraHen is offline  
Old 03/27/2015, 20:59   #15
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
Quote:
Originally Posted by KraHen View Post
Instead of Thread.Sleep(1) in a loop you can use WaitOne with a time parameter.
It won't make any difference. Other than beautifying your code, maybe. Although if you use WaitOne/Sleep in a piece of code, that code shouldn't really appear in lots of places in the source, because you shouldn't Sleep your working threads anywhere.

Probably off-topic:
Depending on the OS, Windows in our case, every thread has a given time span to do its job then when it calls Sleep(...) it sleeps at least the rest of that time span. For Windows it's 20 ms (+/-), so even if you trigger the event you called for WaitOne, it will still wait until the 20 ms are done.

Even more weirder, is that calling something like Thread.Sleep(20) would return one time after 20 ms and one time after like 36 ms.
Anyway, you can't really have a task scheduler that works with millisecond values under like 40. Unless I am wrong and someone knows a way to go have more accuracy, in which case I beg you to show me how.
-impulse- is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[RELEASE] Lua scripts functions
09/27/2020 - SRO PServer Guides & Releases - 9 Replies
Hello. Last release. This is an small documentation I made for myself for some of the functions from the Lua script files used for scripted events and quests. I haven't tested most of them, and in general the whole script system is a bit messy, but if you decide to start creating stuff with it (like new quests or custom events) this may be helpful: InsertPayItemCodeName(int Amount, <String CodeName>) Return value: Unk Result: Set the codename of the item to be given with the...
[Release]Homepage Functions
10/27/2012 - Metin2 PServer Guides & Strategies - 27 Replies
Hallo Epvp, ich hab für euch eine aus langeweile entstandene Functions geschrieben, die euch dabei helfen sollen für eure Homepage bestimmte sachen zu Scripten. Ich werde diese Functions desöfteren aktuallisieren. Der einbau ist ganz einfach. Einfach in eure Index zu den anderen require folgendes hinzufügen: require("./inc/functions_by_tobias.inc.php&q uot;);
[Release] KxaVenom Public v1.2 [VIP Functions]
03/03/2012 - WarRock Hacks, Bots, Cheats & Exploits - 21 Replies
Hey, here is the new Public v1.2. Download: Release.rar VirusTotal: https://www.virustotal.com/file/6848caef5a3550f6e1 3b50d355b5af72cccfb0cd0121141fb05f3a5d3458d9df/ana lysis/1330610586/ Screen: http://i.imgur.com/YW929.png Credits:
[Release]Some functions DekaronServer.exe decompiler
08/14/2011 - Dekaron Private Server - 3 Replies
Some functions DekaronServer.exe decompiler. Hope this helps many people who understand c + + and want to get an emulator or something, with that and much easier to find some offsets and objectstruct, and understand the source code of how it was created server Dekaron and can add things that has the new global or Korean Dekaron. The functions are not 100% decompiler so I have time I will be finishing. DOWNLOAD :mofo:



All times are GMT +1. The time now is 03:01.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.