From 074b2d37ed3531de101e76d330e93c3bef347705 Mon Sep 17 00:00:00 2001 From: rabbet35 Date: Wed, 21 Oct 2020 21:18:32 +1100 Subject: [PATCH] Installed package for java style concurrent RNG, reworked cacti AI. --- RabbetGameEngine/RabbetGameEngine.csproj | 9 ++- RabbetGameEngine/Src/Game/GameInstance.cs | 12 ++-- RabbetGameEngine/Src/Rendering/Renderer.cs | 2 - RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs | 6 +- RabbetGameEngine/Src/World/Entity/Entity.cs | 10 +-- .../Src/World/Entity/EntityCactus.cs | 70 ++++++++++++++----- .../Src/World/Entity/EntityLiving.cs | 4 +- .../Src/World/Entity/EntityPlayer.cs | 4 +- .../Entity/Projectiles/EntityProjectile.cs | 2 +- .../Projectiles/EntityTankProjectile.cs | 2 +- .../Src/World/Entity/Vehicles/EntityTank.cs | 6 +- .../World/Entity/Vehicles/EntityVehicle.cs | 4 +- .../Src/World/{World.cs => Planet.cs} | 22 +++--- RabbetGameEngine/packages.config | 2 + 14 files changed, 96 insertions(+), 59 deletions(-) rename RabbetGameEngine/Src/World/{World.cs => Planet.cs} (97%) diff --git a/RabbetGameEngine/RabbetGameEngine.csproj b/RabbetGameEngine/RabbetGameEngine.csproj index 25d26e6..28f28ee 100644 --- a/RabbetGameEngine/RabbetGameEngine.csproj +++ b/RabbetGameEngine/RabbetGameEngine.csproj @@ -52,6 +52,12 @@ 8.0 + + ..\packages\MedallionRandom.1.1.0\lib\net452\MedallionRandom.dll + + + ..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll @@ -73,6 +79,7 @@ + @@ -122,7 +129,7 @@ - + diff --git a/RabbetGameEngine/Src/Game/GameInstance.cs b/RabbetGameEngine/Src/Game/GameInstance.cs index ed821c2..657a448 100644 --- a/RabbetGameEngine/Src/Game/GameInstance.cs +++ b/RabbetGameEngine/Src/Game/GameInstance.cs @@ -25,7 +25,7 @@ public class GameInstance : GameWindow private static int mouseCenterY;//the y position of the center of the game window private static float dpiY; public EntityPlayer thePlayer; - public World currentPlanet; + public Planet currentPlanet; public GameInstance(int screenWidth, int screenHeight, int initialWindowWidth, int initialWindowHeight, string title) : base(initialWindowWidth, initialWindowHeight, GraphicsMode.Default, title) { @@ -52,14 +52,14 @@ protected override void OnLoad(EventArgs e) DebugInfo.init(); HitboxRenderer.init(); //create and spawn player in new world - thePlayer = new EntityPlayer("Steve", new Vector3(0, 3, 2)); - currentPlanet = new World(); + thePlayer = new EntityPlayer(currentPlanet, "Steve", new Vector3(0, 3, 2)); + currentPlanet = new Planet(0xdeadbeef); for (int i = 0; i < 35; i++) { - currentPlanet.spawnEntityInWorld(new EntityCactus(new Vector3(0, 10, 0))); + currentPlanet.spawnEntityInWorld(new EntityCactus(currentPlanet, new Vector3(0, 10, 0))); } currentPlanet.spawnEntityInWorld(thePlayer); - currentPlanet.spawnEntityInWorld(new EntityTank(new Vector3(5, 10, -5))); + // currentPlanet.spawnEntityInWorld(new EntityTank(currentPlanet, new Vector3(5, 10, -5))); //center mouse in preperation for first person Input.centerMouse(); @@ -101,13 +101,11 @@ protected override void OnFocusedChanged(EventArgs e) /*Each itteration of game logic is done here*/ private void onTick() { - Profiler.beginEndProfile(Profiler.gameLoopName); mouseCenterX = this.X + this.Width / 2; mouseCenterY = this.Y + this.Height / 2; GUIHandler.onTick(); MainGUI.onTick(); currentPlanet.onTick(); - Profiler.beginEndProfile(Profiler.gameLoopName); } diff --git a/RabbetGameEngine/Src/Rendering/Renderer.cs b/RabbetGameEngine/Src/Rendering/Renderer.cs index 4e289e4..b66fe93 100644 --- a/RabbetGameEngine/Src/Rendering/Renderer.cs +++ b/RabbetGameEngine/Src/Rendering/Renderer.cs @@ -64,12 +64,10 @@ public static void onFrame() public static void renderAll() { - Profiler.beginEndProfile(Profiler.renderingName); preRender(); renderWorld(); GUIHandler.drawCurrentGUIScreen(); postRender(); - Profiler.beginEndProfile(Profiler.renderingName); } /*Called before all draw calls*/ diff --git a/RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs b/RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs index a96743c..5e80a24 100644 --- a/RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs +++ b/RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs @@ -7,7 +7,7 @@ namespace RabbetGameEngine.VFX change certain VFX*/ public static class VFXUtil { - public static void doExplosionEffect(World planet, Vector3 location, float radius, float pitch = 0, float yaw = -90, float roll = 0) + public static void doExplosionEffect(Planet planet, Vector3 location, float radius, float pitch = 0, float yaw = -90, float roll = 0) { VFXBase smoke = new VFXPointParticles(location, CustomColor.darkGrey, (25 - (int)radius / 2) + (int)(radius / 2 * radius / 2), radius / 15, 0.15F, true, false, 2F, 0.8F); @@ -36,7 +36,7 @@ public static void doExplosionEffect(World planet, Vector3 location, float radiu planet.spawnVFXInWorld(explosion2); } - public static void doSmallSmokePuffEffect(World planet, Vector3 location, float pitch = 0, float yaw = -90, float roll = 0) + public static void doSmallSmokePuffEffect(Planet planet, Vector3 location, float pitch = 0, float yaw = -90, float roll = 0) { VFXBase smoke = new VFXPointParticles(location, CustomColor.darkGrey, 7, 0.05F, 0.05F, true, false, .5F, 0.8F); @@ -52,7 +52,7 @@ public static void doSmallSmokePuffEffect(World planet, Vector3 location, float planet.spawnVFXInWorld(smoke); } - public static void doDebugSmokeEffect(World planet) + public static void doDebugSmokeEffect(Planet planet) { VFXBase smoke = new VFXPointParticles(new Vector3(0, 2F, 0), new CustomColor(Color.DarkGray), 5, 0.5F, 0.5F, true, false, 2F, 0.5F); smoke.setExpansionResistance(0.05F); diff --git a/RabbetGameEngine/Src/World/Entity/Entity.cs b/RabbetGameEngine/Src/World/Entity/Entity.cs index e78daf6..d7427f7 100644 --- a/RabbetGameEngine/Src/World/Entity/Entity.cs +++ b/RabbetGameEngine/Src/World/Entity/Entity.cs @@ -7,20 +7,22 @@ namespace RabbetGameEngine public class Entity : PositionalObject { - protected World currentPlanet; + protected Planet currentPlanet; protected EntityModel entityModel; protected bool hasModel = false; protected bool isFlying = false; private bool removalFlag = false;// true if this entity should be removed in the next tick protected int existedTicks = 0;//number of ticks this entity has existed for protected bool isPlayer = false; - public Entity() : base() + public Entity(Planet planet) : base() { + currentPlanet = planet; setYAccel(-gravity); } - public Entity(Vector3 spawnPosition) : base(spawnPosition) + public Entity(Planet planet, Vector3 spawnPosition) : base(spawnPosition) { + currentPlanet = planet; setYAccel(-gravity); } @@ -78,7 +80,7 @@ public virtual void onTick() } } - public virtual void setCurrentPlanet(World p) + public virtual void setCurrentPlanet(Planet p) { this.currentPlanet = p; } diff --git a/RabbetGameEngine/Src/World/Entity/EntityCactus.cs b/RabbetGameEngine/Src/World/Entity/EntityCactus.cs index 9f22601..9916858 100644 --- a/RabbetGameEngine/Src/World/Entity/EntityCactus.cs +++ b/RabbetGameEngine/Src/World/Entity/EntityCactus.cs @@ -1,50 +1,84 @@ using OpenTK; using RabbetGameEngine.Models; using RabbetGameEngine.Physics; -using System; namespace RabbetGameEngine { public class EntityCactus : EntityLiving { - private bool turn = true; - private static Random rand = new Random(); - public EntityCactus() : base() + private bool turningRight = false; + private bool turningLeft = false; + private bool walkingFowards = false; + private float rotationSpeed = 2.5F; + public EntityCactus(Planet planet) : base(planet) { this.walkSpeed = 0.025F; this.entityModel = new EntityCactusModel(this); this.hasModel = true; this.collider = new AABB(new Vector3(-0.5F, -0.5F, -0.5F), new Vector3(0.5F, 0.5F, 0.5F), this); this.hasCollider = true; - yaw = (float)rand.NextDouble() * 360; + yaw = (float)currentPlanet.rand.NextDouble() * 360; walkFowards(); } - public EntityCactus(Vector3 pos) : base(pos) + public EntityCactus(Planet planet, Vector3 pos) : base(planet, pos) { this.walkSpeed = 0.025F; this.entityModel = new EntityCactusModel(this); this.hasModel = true; this.collider = new AABB(new Vector3(-0.5F, -0.5F, -0.5F), new Vector3(0.5F, 0.5F, 0.5F), this); this.hasCollider = true; - yaw = (float)rand.NextDouble() * 360; + yaw = (float)currentPlanet.rand.NextDouble() * 360; walkFowards(); } public override void onTick() { - if(rand.Next(0, 25) == 1) - { - turn = !turn; - } + if (currentPlanet.rand.Next() % 100 == 0) + { + walkingFowards = true; + } - if (turn) rotateYaw(-3.0F); else rotateYaw(3.0F); + if (walkingFowards && currentPlanet.rand.Next() % 20 == 0) + { + walkingFowards = false; + } + if (walkingFowards) + { + turningLeft = turningRight = false; + } + else + { + if (currentPlanet.rand.Next() % 100 == 0) + { + turningLeft = true; + } + if (turningLeft && currentPlanet.rand.Next() % 10 == 0) + { + turningLeft = false; + } + if (currentPlanet.rand.Next() % 100 == 0) + { + turningRight = true; + } + if (turningRight && currentPlanet.rand.Next() % 10 == 0) + { + turningRight = false; + } + } + if (walkingFowards) + { + walkFowards(); + } - walkFowards(); + if (turningLeft) + { + yaw -= rotationSpeed; + } - if (rand.Next(0, 50) == 1) - { - jump(); - } - base.onTick();//do last + if (turningRight) + { + yaw += rotationSpeed; + } + base.onTick();//do last } } } diff --git a/RabbetGameEngine/Src/World/Entity/EntityLiving.cs b/RabbetGameEngine/Src/World/Entity/EntityLiving.cs index 2e084ee..6cec13f 100644 --- a/RabbetGameEngine/Src/World/Entity/EntityLiving.cs +++ b/RabbetGameEngine/Src/World/Entity/EntityLiving.cs @@ -35,14 +35,14 @@ public class EntityLiving : Entity is set to true. To detect if an action is requested, check the index. e.g: if(actions[Action.attack])*/ protected bool[] actions = new bool[EntityLiving.actionsCount]; - public EntityLiving() : base() + public EntityLiving(Planet planet) : base(planet) { frontVector = new Vector3(0.0F, 0.0F, -1.0F); upVector = new Vector3(0.0F, 1.0F, 0.0F); interactTimer = new TickTimer(interactIntervalSeconds); } - public EntityLiving(Vector3 pos) : base(pos) + public EntityLiving(Planet planet, Vector3 pos) : base(planet, pos) { frontVector = new Vector3(0.0F, 0.0F, -1.0F); upVector = new Vector3(0.0F, 1.0F, 0.0F); diff --git a/RabbetGameEngine/Src/World/Entity/EntityPlayer.cs b/RabbetGameEngine/Src/World/Entity/EntityPlayer.cs index 8d37321..b3d7d3f 100644 --- a/RabbetGameEngine/Src/World/Entity/EntityPlayer.cs +++ b/RabbetGameEngine/Src/World/Entity/EntityPlayer.cs @@ -12,7 +12,7 @@ public class EntityPlayer : EntityLiving public bool debugScreenOn = false; public static readonly Vector3 eyeOffset = new Vector3(0.0F, 0.62F, 0.0F); - public EntityPlayer(string name) : base() + public EntityPlayer(Planet planet, string name) : base(planet) { isPlayer = true; this.playerName = name; @@ -20,7 +20,7 @@ public EntityPlayer(string name) : base() this.collider = new AABB(new Vector3(-0.5F, -1, -0.5F), new Vector3(0.5F, 1, 0.5F), this); this.hasCollider = true; } - public EntityPlayer(string name, Vector3 spawnPosition) : base(spawnPosition) + public EntityPlayer(Planet planet, string name, Vector3 spawnPosition) : base(planet, spawnPosition) { isPlayer = true; this.playerName = name; diff --git a/RabbetGameEngine/Src/World/Entity/Projectiles/EntityProjectile.cs b/RabbetGameEngine/Src/World/Entity/Projectiles/EntityProjectile.cs index e84a5d4..3e199c2 100644 --- a/RabbetGameEngine/Src/World/Entity/Projectiles/EntityProjectile.cs +++ b/RabbetGameEngine/Src/World/Entity/Projectiles/EntityProjectile.cs @@ -7,7 +7,7 @@ class EntityProjectile : Entity, IDisposable { protected float maxExistedTicks; - public EntityProjectile(Vector3 pos, Vector3 direction, float initialVelocity = 2.5F, float maxLivingSeconds = 20) : base(pos) + public EntityProjectile(Planet p, Vector3 pos, Vector3 direction, float initialVelocity = 2.5F, float maxLivingSeconds = 20) : base(p, pos) { airResistance = 0.001F; velocity += direction * initialVelocity; diff --git a/RabbetGameEngine/Src/World/Entity/Projectiles/EntityTankProjectile.cs b/RabbetGameEngine/Src/World/Entity/Projectiles/EntityTankProjectile.cs index 0a794da..0ca002d 100644 --- a/RabbetGameEngine/Src/World/Entity/Projectiles/EntityTankProjectile.cs +++ b/RabbetGameEngine/Src/World/Entity/Projectiles/EntityTankProjectile.cs @@ -6,7 +6,7 @@ namespace RabbetGameEngine { class EntityTankProjectile : EntityProjectile { - public EntityTankProjectile(Vector3 pos, Vector3 direction, float barrelPitch, float initialYaw) : base(pos, direction) + public EntityTankProjectile(Planet p, Vector3 pos, Vector3 direction, float barrelPitch, float initialYaw) : base(p, pos, direction) { this.yaw = initialYaw - 90; this.pitch = barrelPitch; diff --git a/RabbetGameEngine/Src/World/Entity/Vehicles/EntityTank.cs b/RabbetGameEngine/Src/World/Entity/Vehicles/EntityTank.cs index 1af85c4..2e36e40 100644 --- a/RabbetGameEngine/Src/World/Entity/Vehicles/EntityTank.cs +++ b/RabbetGameEngine/Src/World/Entity/Vehicles/EntityTank.cs @@ -13,7 +13,7 @@ public class EntityTank : EntityVehicle private float barrelPitch; public static readonly float barrelLength = 6.75F; private TickTimer fireTimer; - public EntityTank() : base() + public EntityTank(Planet p) : base(p) { this.entityModel = new EntityTankModel(this); this.hasModel = true; @@ -21,7 +21,7 @@ public EntityTank() : base() this.hasCollider = true; fireTimer = new TickTimer(1F / roundsPerSecond); } - public EntityTank(Vector3 initialPos) : base(initialPos) + public EntityTank(Planet p, Vector3 initialPos) : base(p, initialPos) { this.entityModel = new EntityTankModel(this); this.hasModel = true; @@ -93,7 +93,7 @@ protected override void moveByMovementVector() public void onDriverAttack() { Vector3 muzzleLocation = getMuzzleLocation(); - currentPlanet.spawnEntityInWorld(new EntityTankProjectile(muzzleLocation, getMuzzleFrontVector(), barrelPitch, bodyYaw)); + currentPlanet.spawnEntityInWorld(new EntityTankProjectile(currentPlanet, muzzleLocation, getMuzzleFrontVector(), barrelPitch, bodyYaw)); VFXUtil.doSmallSmokePuffEffect(currentPlanet, muzzleLocation, (float)barrelPitch, (float)bodyYaw); } diff --git a/RabbetGameEngine/Src/World/Entity/Vehicles/EntityVehicle.cs b/RabbetGameEngine/Src/World/Entity/Vehicles/EntityVehicle.cs index a2c6265..1accba7 100644 --- a/RabbetGameEngine/Src/World/Entity/Vehicles/EntityVehicle.cs +++ b/RabbetGameEngine/Src/World/Entity/Vehicles/EntityVehicle.cs @@ -15,7 +15,7 @@ public class EntityVehicle : Entity protected float driveSpeed = defaultDriveSpeed; protected float turnRate = defaultTurnRate; protected bool playerDriving = false; - public EntityVehicle() : base() + public EntityVehicle(Planet p) : base(p) { frontVector = new Vector3(0.0F, 0.0F, -1.0F); upVector = new Vector3(0.0F, 1.0F, 0.0F); @@ -23,7 +23,7 @@ public EntityVehicle() : base() mountingOffset = new Vector3(0.0F, 1.9F, 0.0F); } - public EntityVehicle(Vector3 pos) : base(pos) + public EntityVehicle(Planet p, Vector3 pos) : base(p, pos) { frontVector = new Vector3(0.0F, 0.0F, -1.0F); upVector = new Vector3(0.0F, 1.0F, 0.0F); diff --git a/RabbetGameEngine/Src/World/World.cs b/RabbetGameEngine/Src/World/Planet.cs similarity index 97% rename from RabbetGameEngine/Src/World/World.cs rename to RabbetGameEngine/Src/World/Planet.cs index c3b919f..084efa1 100644 --- a/RabbetGameEngine/Src/World/World.cs +++ b/RabbetGameEngine/Src/World/Planet.cs @@ -1,16 +1,18 @@ -using OpenTK; +using Medallion; +using OpenTK; using RabbetGameEngine.Debugging; using RabbetGameEngine.Models; using RabbetGameEngine.Physics; using RabbetGameEngine.SubRendering; using RabbetGameEngine.VFX; +using System; using System.Collections.Generic; using System.Linq; namespace RabbetGameEngine { /*This class will be the abstraction of any environment constructed for the player and entities to exist in.*/ - public class World + public class Planet { private ModelDrawable groundModel; private ModelDrawable wallsModel; @@ -25,11 +27,12 @@ public class World private string wallTextureName = "transparent"; private string groundTextureName = "wood"; private string groundWallShaderName = "EntityWorld_F"; - + private Random random; ModelDrawableInstanced test; - public World() + public Planet(long seed) { + random = Rand.CreateJavaRandom(seed); fogColor = CustomColor.grey.toNormalVec3(); skyColor = CustomColor.darkGrey.toNormalVec3(); buildSkyBox(); @@ -252,9 +255,7 @@ private void tickVFX() private void doEntityCollisions() { - Profiler.beginEndProfile(Profiler.entCollisionsName); CollisionHandler.collideEntities(entities); - Profiler.beginEndProfile(Profiler.entCollisionsName); } @@ -301,15 +302,8 @@ public ModelDrawable getWallsModel() public void spawnEntityInWorld(Entity theEntity) { - theEntity.setCurrentPlanet(this); - entities.Add(entityIDItterator, theEntity); - /*if(theEntity.getHasCollider()) - { - entityColliders.Add(entityIDItterator, theEntity.getCollider()); - }*/ - entityIDItterator++; } @@ -337,5 +331,7 @@ public void onLeavingWorld() { test.delete(); } + + public Random rand { get => this.random; } } } diff --git a/RabbetGameEngine/packages.config b/RabbetGameEngine/packages.config index 14a78f8..84e33dc 100644 --- a/RabbetGameEngine/packages.config +++ b/RabbetGameEngine/packages.config @@ -1,4 +1,6 @@  + + \ No newline at end of file