Quote:
Originally Posted by shadowman123
Well Im Abit DisAppointed but i Can Handle it At last But Please When you Say smthing is Bad Tell me Y it is for Screen System idk whats Wrong with it..Can u ? .. For Threads i Searched for it But All i got is Different Techniques of Making Thread For Example Using This Way
Code:
Thread MyThread = new Thread(new ThreadStarter(Target));
MyThread.Start();
MyThread.Join();
|
Threading is so, so, so simple, Why do people over do it?
It's as simple as:
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ConquerSource.Game;
using System.Diagnostics;
namespace ConquerSource.Core
{
public class Threading
{
static TIME _LastCheck;
public static void Fireup()
{
_LastCheck = TIME.Now;
//Main thread
new Thread(Core).Start();
Program.WriteLine("[Threading] Core threads has been created and started.");
}
public static void Core()
{
while (true)
{
TIME CurrentTime = TIME.Now;
if (CurrentTime.Time >= _LastCheck.Time)
{
_LastCheck = TIME.Now;
Stamina_Check();
}
Thread.Sleep(100);
}
}
private static void Stamina_Check()
{
foreach (GameClient client in Kernel.GamePool.Values)
{
TIME CurrentTime = TIME.Now;
double Time = 0;
bool Quick = false;
if (client.Char.Action == ConquerAction.Sit)
{
Time = 800;
Quick = true;
}
else
Time = 1200;
if (client.Char.StaminaStamp.Time <= CurrentTime.Time)
{
client.Char.StaminaStamp = CurrentTime.AddMilliseconds((int)Time);
if (client.Char.Stamina != 100)
{
switch (Quick)
{
case false:
{
if (client.Char.Stamina <= 96)//7?
client.Char.Stamina += 3;
else
client.Char.Stamina = 100;
break;
}
case true:
{
if (client.Char.Stamina <= 93)//10?
client.Char.Stamina += 7;
else
client.Char.Stamina = 100;
break;
}
}
}
}
}
}
}
}
I wrote that over a year ago, there's no need for a load of fancy threading shit, keep it simple, keep it good.
Note: Over a year ago, Yes I should be going through the dictionary as an array for faster speeds, and the stamina code is abit fucked up, ontop of the initial thread check, but it works, very well.