LockInt

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game.LockNumbers
{
public struct LockInt
{
int vbase;
int vadd;
static readonly int base_flag = 29173;
static readonly int add_flag = 16829;
public int Value{
get { return ( (~vbase + base_flag) >> 1) + vadd + add_flag; }
set
{
var _base = (int)(value * 0.37134f);
vbase = (_base << 1) - base_flag;
vbase = ~vbase;
vadd = (value - _base);
vadd -= add_flag;
}
}
public LockInt(int v)
{
vbase = 0;
vadd = 0;
Value = v;
}

public static implicit operator int(LockInt v)
{
return v.Value;
}

public static implicit operator LockInt(int b)
{
LockInt d ;
d.vadd = 0;
d.vbase = 0;
d.Value = b;
return d;
}

public static LockInt operator + (LockInt v1, LockInt v2)
{
return v1.Value + v2.Value;
}
public static LockInt operator -(LockInt v1, LockInt v2)
{
return v1.Value - v2.Value;
}
public static LockInt operator *(LockInt v1, LockInt v2)
{
return v1.Value * v2.Value;
}
public static LockInt operator /(LockInt v1, LockInt v2)
{
return v1.Value / v2.Value;
}
}
}

lockint +=1;

locakint =1;

posted @ 2017-07-26 13:55  rexzhao  阅读(112)  评论(0编辑  收藏  举报