Architecture shift and not working render
This commit is contained in:
parent
a54f49d188
commit
e88327799b
5 changed files with 65 additions and 84 deletions
|
|
@ -1,55 +1,42 @@
|
|||
#include "world.h"
|
||||
#include "components.h"
|
||||
#include <raylib.h>
|
||||
|
||||
World::World(){
|
||||
this->entities = new Entity[World::GRID_SIZE];
|
||||
this->entities = {};
|
||||
this->seconds_per_tick = 0;
|
||||
this->clock = 0;
|
||||
}
|
||||
|
||||
World::~World(){
|
||||
delete [] this->entities;
|
||||
delete [] this->processables;
|
||||
delete [] this->drawables;
|
||||
}
|
||||
|
||||
void World::setup(){
|
||||
this->processables_count = 0;
|
||||
this->drawables_count = 0;
|
||||
|
||||
IProcessable* temp_processables[World::GRID_SIZE];
|
||||
IDrawable* temp_drawables[World::GRID_SIZE];
|
||||
|
||||
for(int i = 0; i < World::GRID_SIZE; i++) {
|
||||
// Get all processables and drawables as pointers to store later.
|
||||
IProcessable* processable = dynamic_cast<IProcessable*>(&this->entities[i]);
|
||||
IDrawable* drawable = dynamic_cast<IDrawable*>(&this->entities[i]);
|
||||
|
||||
if (processable != nullptr) {
|
||||
temp_processables[this->processables_count] = processable;
|
||||
this->processables_count++;
|
||||
}
|
||||
if (drawable != nullptr) {
|
||||
temp_drawables[this->drawables_count] = drawable;
|
||||
this->drawables_count++;
|
||||
}
|
||||
}
|
||||
|
||||
// Store processables and drawables
|
||||
this->processables = new IProcessable*[this->processables_count];
|
||||
this->drawables = new IDrawable*[this->drawables_count];
|
||||
|
||||
for(int i = 0; i < this->processables_count; i++)
|
||||
this->processables[i] = temp_processables[i];
|
||||
for(int i = 0; i < this->drawables_count; i++)
|
||||
this->drawables[i] = temp_drawables[i];
|
||||
|
||||
// Call ready on all readibles
|
||||
for(int i = 0; i < World::GRID_SIZE; i++)
|
||||
{
|
||||
IReadible* readible = dynamic_cast<IReadible*>(&this->entities[i]);
|
||||
if (readible != nullptr)
|
||||
readible->ready();
|
||||
}
|
||||
|
||||
for(int i = 0; i < this->entities.size(); i++)
|
||||
this->entities[i].ready();
|
||||
}
|
||||
|
||||
void World::process(){
|
||||
this->clock += GetFrameTime();
|
||||
|
||||
for(int i = 0; i < this->entities.size(); i++) {
|
||||
this->entities[i].process();
|
||||
if (this->clock>=this->seconds_per_tick) {
|
||||
this->entities[i].tick();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->clock>=this->seconds_per_tick) {
|
||||
this->clock = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void World::draw() {
|
||||
for(int i = 0; i< this->entities.size(); i++) {
|
||||
this->entities[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
World create_world_with(float seconds_per_tick){
|
||||
World result = World();
|
||||
|
||||
result.seconds_per_tick = seconds_per_tick;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue