2021-06-03 15:05:45 +12:00
*| JavaECS*
2021-06-05 02:44:29 +12:00
# JavaECS Docs
2021-05-06 13:44:57 +12:00
2021-06-05 02:44:29 +12:00
### [View the Documentation](./docs/overview.md)
2021-05-06 14:22:22 +12:00
2021-06-05 02:44:29 +12:00
## *About Entity-Component-Systems*
2021-05-06 14:22:22 +12:00
2021-06-05 02:44:29 +12:00
Traditional game-engine designs typically follow the standard functional or object-oriented design paradigms.
This choice of paradigm is as important as it is in typical applications.
A functional-paradigm game usually focuses on a 'this-then-that' model, e.g.:
2021-05-06 14:22:22 +12:00
***Simple Driving Game***
``` py
turn = GetTurn()
TurnCar(turn)
if IsCollided(): # and other checks
GameOver()
else:
DrawNextFrame()
turn = GetTurn()
```
Such a system works well for some game-designs; it is simplistic and follows a deterministic sequence of steps. But it lacks scalability and extensibility.
2021-06-05 02:44:29 +12:00
2021-05-06 14:22:22 +12:00
An Object-Oriented approach could be used instead:
``` py
# Create a base-class that is a vehicle, with basic properties:
class Vehicle:
position = [x,y]
IsCrashed = False
def CalcTurn():
pass
def IsCollided():
pass
# Create the PlayerVehicle class which extends Vehicle to include the player input method
class PlayerVehicle(Vehicle):
def GetPlayerInput():
pass
def GameLoop():
vehicles[] = GetAllVehichles()
allCollided = False
while not allCollided:
for v in vehicles:
turnAmount
if v is PlayerVehicle:
turnAmount = v.GetPlayerInput()
else:
turnAmount = v.CalcTurn()
v.TurnVehicle()
if v.IsCollided():
v.IsCrashed = True
anyNotCollided = False
for v in vehicles:
if v.IsCrashed = False:
anyNotCollided = True
break
2021-06-05 02:44:29 +12:00
```
2021-05-06 14:22:22 +12:00
2021-06-05 02:44:29 +12:00
Which allows the instancing of objects. Each action also results in an objective state, which can be simply compared to determine the result.
2021-05-06 14:22:22 +12:00
2021-06-05 02:44:29 +12:00
ECS are typically built on object-oriented ideas, but make specfic attempts to reduce overheads that come from object-oriented ideas.
The primary reduction made in ECS is to eliminate or otherwise minimise inhertance cycles to reduce the amount of virtual calls required.