Skip to content

Commit

Permalink
Merge pull request #153 from asdawej/dev-objpool
Browse files Browse the repository at this point in the history
Add objpool
  • Loading branch information
asdawej authored Mar 29, 2024
2 parents b12844e + 6721fe7 commit cd37156
Show file tree
Hide file tree
Showing 35 changed files with 526 additions and 219 deletions.
3 changes: 3 additions & 0 deletions CAPI/python/PyAPI/DebugAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def PrintSweeper(self) -> None:
)
self.__logger.info('************************\n')

def PrintTeam(self) -> None:
pass

def PrintSelfInfo(self) -> None:
sweeper = self.__logic.GetSelfInfo()
self.__logger.info('******sweeper Info******')
Expand Down
4 changes: 2 additions & 2 deletions CAPI/python/PyAPI/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def GetHomeHp(self) -> int:
pass

@abstractmethod
def GetEnergy(self) -> int:
def GetMoney(self) -> int:
pass

@abstractmethod
Expand Down Expand Up @@ -214,7 +214,7 @@ def GetHomeHp(self) -> int:
pass

@abstractmethod
def GetEnergy(self) -> int:
def GetMoney(self) -> int:
pass

@abstractmethod
Expand Down
5 changes: 3 additions & 2 deletions CAPI/python/PyAPI/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import PyAPI.structures as THUAI7
from PyAPI.utils import Proto2THUAI7, AssistFunction
from PyAPI.API import SweeperAPI, TeamAPI
from PyAPI.DebugAPI import SweeperDebugAPI, TeamDebugAPI
from PyAPI.AI import Setting
from PyAPI.Communication import Communication
from PyAPI.State import State
Expand Down Expand Up @@ -851,11 +852,11 @@ def Main(

if platform.system().lower() == 'windows':
os.system(
f'mkdir '{os.path.dirname(os.path.dirname(os.path.realpath(__file__)))}\\logs''
f'mkdir "{os.path.dirname(os.path.dirname(os.path.realpath(__file__)))}\\logs"'
)
else:
os.system(
f'mkdir -p '{os.path.dirname(os.path.dirname(os.path.realpath(__file__)))} / logs''
f'mkdir -p "{os.path.dirname(os.path.dirname(os.path.realpath(__file__)))}/logs"'
)

fileHandler = logging.FileHandler(
Expand Down
8 changes: 4 additions & 4 deletions logic/Client/Interact/JsonInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static string[] JsonInteract()

if (File.Exists(filepath))
{
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
StreamReader file = new StreamReader(fs, System.Text.Encoding.Default);
JsonTextReader reader = new JsonTextReader(file);//解析json模块
FileStream fs = new(filepath, FileMode.Open, FileAccess.ReadWrite);
StreamReader file = new(fs, System.Text.Encoding.Default);
JsonTextReader reader = new(file);//解析json模块
JObject o = (JObject)JToken.ReadFrom(reader);
string ip = o["ip"].ToString();
string port = o["port"].ToString();
Expand Down Expand Up @@ -51,7 +51,7 @@ static string[] JsonInteract()
public static string[] FileInteract()
{
string[] cominfo = new string[10];
ConfigData d = new ConfigData();
ConfigData d = new();
if (d.Commands.Launched == false)
{
cominfo[0] = d.Commands.IP;
Expand Down
1 change: 0 additions & 1 deletion logic/GameClass/GameObj/Areas/Asteroid.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Preparation.Utility;
using System;

namespace GameClass.GameObj.Areas;

Expand Down
1 change: 0 additions & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Preparation.Utility;
using System;

namespace GameClass.GameObj.Areas;

Expand Down
1 change: 0 additions & 1 deletion logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Preparation.Interface;
using Preparation.Utility;
using System;

namespace GameClass.GameObj.Areas;

Expand Down
2 changes: 0 additions & 2 deletions logic/GameClass/GameObj/Areas/Resource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Preparation.Utility;
using System;
using System.Threading;

namespace GameClass.GameObj.Areas;

Expand Down
1 change: 0 additions & 1 deletion logic/GameClass/GameObj/Areas/Shadow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Preparation.Utility;
using System;

namespace GameClass.GameObj.Areas;

Expand Down
1 change: 0 additions & 1 deletion logic/GameClass/GameObj/Areas/Wormhole.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Preparation.Interface;
using Preparation.Utility;
using System;
using System.Collections.Generic;

namespace GameClass.GameObj.Areas;
Expand Down
3 changes: 0 additions & 3 deletions logic/GameClass/GameObj/Bullets/Laser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Preparation.Interface;
using Preparation.Utility;
using System;
using System.Threading;

namespace GameClass.GameObj.Bullets;

Expand Down
4 changes: 2 additions & 2 deletions logic/GameClass/GameObj/Bullets/Missile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Preparation.Utility;
using Preparation.Utility;
using System;

namespace GameClass.GameObj.Bullets;

Expand Down
8 changes: 3 additions & 5 deletions logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections.Generic;
using System.Threading;
using GameClass.GameObj.Areas;
using GameClass.MapGenerator;
using Preparation.Interface;
using Preparation.Utility;
using System;
using GameClass.GameObj.Areas;
using System.Linq;
using GameClass.MapGenerator;
using System.Collections.Generic;

namespace GameClass.GameObj
{
Expand Down
4 changes: 2 additions & 2 deletions logic/GameClass/GameObj/Map/MapGameTimer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Preparation.Utility;
using System;
using System.Threading;
using Preparation.Utility;
using ITimer = Preparation.Interface.ITimer;

namespace GameClass.GameObj
Expand Down
49 changes: 25 additions & 24 deletions logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using GameClass.GameObj.Bullets;
using Preparation.Interface;
using Preparation.Utility;
using GameClass.GameObj.Bullets;
using GameClass.GameObj.Modules;
using GameClass.GameObj.Occupations;
using Preparation.Interface;
using Preparation.Utility;

namespace GameClass.GameObj;

Expand All @@ -18,7 +17,9 @@ public override bool IgnoreCollideExecutor(IGameObj targetObj)
{
if (IsRemoved)
return true;
if (targetObj.Type == GameObjType.Ship && XY.DistanceCeil3(targetObj.Position, this.Position) < this.Radius + targetObj.Radius - GameData.AdjustLength)
if (targetObj.Type == GameObjType.Ship
&& XY.DistanceCeil3(targetObj.Position, Position)
< Radius + targetObj.Radius - GameData.AdjustLength)
return true;
return false;
}
Expand Down Expand Up @@ -355,7 +356,7 @@ public bool ResetShipState(long state, RunningStateType running = RunningStateTy
lock (actionLock)
{
if (state != stateNum) return false;
this.runningState = running;
runningState = running;
whatInteractingWith = (GameObj?)obj;
shipState = value;
++stateNum;
Expand All @@ -367,7 +368,7 @@ public bool ResetShipStateInOneThread(long state, RunningStateType running = Run
lock (actionLock)
{
if (state != stateNum) return false;
this.runningState = running;
runningState = running;
whatInteractingWith = (GameObj?)obj;
shipState = value;
return true;
Expand All @@ -377,7 +378,7 @@ public bool StartThread(long stateNum, RunningStateType runningState)
{
lock (actionLock)
{
if (this.StateNum == stateNum)
if (StateNum == stateNum)
{
this.runningState = runningState;
return true;
Expand Down Expand Up @@ -408,16 +409,16 @@ public bool Commandable()
public Ship(int initRadius, ShipType shipType, MoneyPool moneyPool) :
base(GameData.PosNotInGame, initRadius, GameObjType.Ship)
{
this.CanMove.SetROri(false);
this.IsRemoved.SetROri(true);
this.Occupation = OccupationFactory.FindIOccupation(this.ShipType = shipType);
this.ViewRange = this.Occupation.ViewRange;
this.HP = new(this.Occupation.MaxHp);
this.Armor = new(this.Occupation.BaseArmor);
this.Shield = new(this.Occupation.BaseShield);
this.MoveSpeed.SetROri(this.orgMoveSpeed = Occupation.MoveSpeed);
this.MoneyPool = moneyPool;
(this.producerType, this.constructorType, this.armorType, this.shieldType, this.weaponType) = this.ShipType switch
CanMove.SetROri(false);
IsRemoved.SetROri(true);
Occupation = OccupationFactory.FindIOccupation(ShipType = shipType);
ViewRange = Occupation.ViewRange;
HP = new(Occupation.MaxHp);
Armor = new(Occupation.BaseArmor);
Shield = new(Occupation.BaseShield);
MoveSpeed.SetROri(orgMoveSpeed = Occupation.MoveSpeed);
MoneyPool = moneyPool;
(producerType, constructorType, armorType, shieldType, weaponType) = ShipType switch
{
ShipType.CivilShip => (
ProducerType.Producer1,
Expand All @@ -442,12 +443,12 @@ public Ship(int initRadius, ShipType shipType, MoneyPool moneyPool) :
),
_ => (ProducerType.Null, ConstructorType.Null, ArmorType.Null, ShieldType.Null, WeaponType.Null)
};
(this.producer, this.constructor, this.armor, this.shield, this.weapon) = (
ModuleFactory.FindIProducer(this.ShipType, this.producerType),
ModuleFactory.FindIConstructor(this.ShipType, this.constructorType),
ModuleFactory.FindIArmor(this.ShipType, this.armorType),
ModuleFactory.FindIShield(this.ShipType, this.shieldType),
ModuleFactory.FindIWeapon(this.ShipType, this.weaponType)
(producer, constructor, armor, shield, weapon) = (
ModuleFactory.FindIProducer(ShipType, producerType),
ModuleFactory.FindIConstructor(ShipType, constructorType),
ModuleFactory.FindIArmor(ShipType, armorType),
ModuleFactory.FindIShield(ShipType, shieldType),
ModuleFactory.FindIWeapon(ShipType, weaponType)
);
}
}
Loading

0 comments on commit cd37156

Please sign in to comment.