I'm trying to build my own entity framework of how game entities are initialized and their codes executed.
I'd like to know if there are already existing entity engines so I can learn from them just in case that I don't waste my time on discovering something that already exists.
I have an idea and I'm currently writing code for it:
There's a game entity pointer array and a game entity heap. The game entity pointer array contains a 16-bit pointer to the game entity which is in the game entity heap. If I only had the heap, the entity execution order would be fragmented. Let's say I have 12 entities that can be on screen at the same time.
According to how I see a game engine, the entities #5, #6 and #7 should run after entity #4.
So because of this, I have an array of pointers that fills like this:
Now begins the sorting
Sorting by moving the giant entity structs would be ultra stupid so it's better to move the pointers.
Every entity has its data structure like this: (Note, I'm actually using ASM and not C++, but I like to write C++ code before doing ASM so that I know what I'm doing)
The physics code works for each entity the same, but acts differently because for example a player can't move freely up and down because it's not a bird, but parakoopas can. These flags are checked and then the usual code executes like:
I mean, there's tons of code, but you basically know what I mean.
Every entity has its code for execution for example for AI or colissions with powerups or each other.
What do you think? Would this work?
I'd like to know if there are already existing entity engines so I can learn from them just in case that I don't waste my time on discovering something that already exists.
I have an idea and I'm currently writing code for it:
There's a game entity pointer array and a game entity heap. The game entity pointer array contains a 16-bit pointer to the game entity which is in the game entity heap. If I only had the heap, the entity execution order would be fragmented. Let's say I have 12 entities that can be on screen at the same time.
Code:
Heap: x,x,x,x,x,x,x,x,x,x,x,x
Heap: 0,1,2,3,4,x,x,x,x,x,x,x Adding 5 entities
Heap: 0,1,x,x,4,x,x,x,x,x,x,x Removed entities 2 and 3
Heap: 0,1,5,6,4,7,x,x,x,x,x,x Added 3 new entities
Heap: 0,1,2,3,4,x,x,x,x,x,x,x Adding 5 entities
Heap: 0,1,x,x,4,x,x,x,x,x,x,x Removed entities 2 and 3
Heap: 0,1,5,6,4,7,x,x,x,x,x,x Added 3 new entities
According to how I see a game engine, the entities #5, #6 and #7 should run after entity #4.
Code:
Heap: 0,1,x,x,4,5,6,7,x,x,x,x
Heap: 0,1,x,x,4,5,6,7,8,9,A,B Added some more entities
Cannot add any more entities without destroying the code execution order.
Heap: 0,1,x,x,4,5,6,7,8,9,A,B Added some more entities
Cannot add any more entities without destroying the code execution order.
So because of this, I have an array of pointers that fills like this:
Code:
Array: x,x,x,x,x,x,x,x,x,x,x,x
Array: 0,1,2,3,4,5,6,7,x,x,x,x Add 8 entities
Array: 0,x,x,x,x,x,6,7,x,x,x,x Removed some entities
Array: 0,x,x,x,x,x,6,7,8,9,A,B Trying to add more
Array: 0,1,2,3,4,5,6,7,x,x,x,x Add 8 entities
Array: 0,x,x,x,x,x,6,7,x,x,x,x Removed some entities
Array: 0,x,x,x,x,x,6,7,8,9,A,B Trying to add more
Now begins the sorting
Code:
Array: 0,6,7,8,9,A,B,C,D,E,x,x Sorted and added more entities
Sorting by moving the giant entity structs would be ultra stupid so it's better to move the pointers.
Every entity has its data structure like this: (Note, I'm actually using ASM and not C++, but I like to write C++ code before doing ASM so that I know what I'm doing)
Code:
class instance
{
char State
short ID
char* Code // (pointer to pointer to this instance's code in ROM)
uint24_t X // Low byte is the fraction for subpixels and subsubpixels, mid byte is for moving on the screen page and high byte is for moving through multiple screens
uint24_t Y
char Attributes
// Attributes: 7=visible,6=solid,5=enablecontrol,4=substitutivecontrol
// 3:0=qualifiers{3=enemy,2=neutral,1=friend,0=player}
char BehaviorTemplateLow
// Behaviors:
// 7=disablePhysics,6=topBounce,5=bottomBounce,4=horizontalBounce,
// 3=freeUpDown,2=freeRightLeft,1=enableGravity,0=enableJump
char BehaviorTemplateHigh
// Behaviors:
// 7=enablePseudo3D,6=Zfree,5=Zgravity,4=Zbounce
// 3=Zjump,2=Zjetpack,1=ZcontrolByJump,0=ZcontrolByUp
_tButtons ControlSubstitutive // Over here are the buttons that are pressed for the entity by artificial intelligence
char ControlPtr // Pointer to global control that controls the object
char SpeedX
char SpeedY
char AccX
char AccY_or_Jump
char DecX
char DecY_or_Gravity
char AnimAttributes
// 7=stopped,6:5=forcedPaletteIndex,4=forceOwnPalette
// 3=loop,2=returnToStart,1=verticalMirror,0=horizontalMirror
char AnimNumber
char AnimSpeedCounter
char UserVariables[6]
char JumpTimeCounter
char JumpTimeMax
char Z
char SpeedZ // Used if pseudo3D is on
char AccZ_or_ZJump
char DecZ_or_ZGravity
}
{
char State
short ID
char* Code // (pointer to pointer to this instance's code in ROM)
uint24_t X // Low byte is the fraction for subpixels and subsubpixels, mid byte is for moving on the screen page and high byte is for moving through multiple screens
uint24_t Y
char Attributes
// Attributes: 7=visible,6=solid,5=enablecontrol,4=substitutivecontrol
// 3:0=qualifiers{3=enemy,2=neutral,1=friend,0=player}
char BehaviorTemplateLow
// Behaviors:
// 7=disablePhysics,6=topBounce,5=bottomBounce,4=horizontalBounce,
// 3=freeUpDown,2=freeRightLeft,1=enableGravity,0=enableJump
char BehaviorTemplateHigh
// Behaviors:
// 7=enablePseudo3D,6=Zfree,5=Zgravity,4=Zbounce
// 3=Zjump,2=Zjetpack,1=ZcontrolByJump,0=ZcontrolByUp
_tButtons ControlSubstitutive // Over here are the buttons that are pressed for the entity by artificial intelligence
char ControlPtr // Pointer to global control that controls the object
char SpeedX
char SpeedY
char AccX
char AccY_or_Jump
char DecX
char DecY_or_Gravity
char AnimAttributes
// 7=stopped,6:5=forcedPaletteIndex,4=forceOwnPalette
// 3=loop,2=returnToStart,1=verticalMirror,0=horizontalMirror
char AnimNumber
char AnimSpeedCounter
char UserVariables[6]
char JumpTimeCounter
char JumpTimeMax
char Z
char SpeedZ // Used if pseudo3D is on
char AccZ_or_ZJump
char DecZ_or_ZGravity
}
The physics code works for each entity the same, but acts differently because for example a player can't move freely up and down because it's not a bird, but parakoopas can. These flags are checked and then the usual code executes like:
Code:
SpeedX+=IsBitOne(ControlSubstitutive,RightButton)*AccX
X+=SpeedX
X+=SpeedX
I mean, there's tons of code, but you basically know what I mean.
Every entity has its code for execution for example for AI or colissions with powerups or each other.
What do you think? Would this work?