Added a world state object

This commit is contained in:
Ludovic 'Archivist' Lagouardette 2023-10-02 15:11:24 +02:00
parent fc534fd8e1
commit ce09bd79e9
3 changed files with 15 additions and 3 deletions

View file

@ -9,13 +9,14 @@ import std.format;
import std.conv : to; import std.conv : to;
import core.time; import core.time;
import toki.symbols; import toki.symbols;
import world.screen; import world;
extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ]; extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ];
int main(string[] args) { int main(string[] args) {
try { try {
worldContents = new WorldObjectList;
InitWindow(800,600,"Unnamed project"); InitWindow(800,600,"Unnamed project");
log(LogLevel.INFOHIGH, "Window Initialized..."); log(LogLevel.INFOHIGH, "Window Initialized...");
Screen.x = Screen.y = 0; Screen.x = Screen.y = 0;
@ -58,6 +59,12 @@ int main(string[] args) {
log(LogLevel.INFOLOW, "Render start..."); log(LogLevel.INFOLOW, "Render start...");
BeginDrawing();{ BeginDrawing();{
ClearBackground(Colors.WHITE); ClearBackground(Colors.WHITE);
foreach (obj; worldContents)
{
obj.render(deltaTime);
}
DrawFPS(0,0); DrawFPS(0,0);
auto pos = GetMousePosition(); auto pos = GetMousePosition();
DrawText(toStringz(format("%f, %f", pos.x, pos.y)), 0, 24, 20, Colors.GREEN); DrawText(toStringz(format("%f, %f", pos.x, pos.y)), 0, 24, 20, Colors.GREEN);

View file

@ -4,4 +4,7 @@ public {
import world.world_object; import world.world_object;
import world.entity; import world.entity;
import world.rigid; import world.rigid;
import world.screen;
WorldObjectList worldContents;
} }

View file

@ -1,12 +1,14 @@
module world.world_object; module world.world_object;
import utils.shapes; import utils.shapes;
import utils.indexedarray;
alias WorldObjectList = IndexedArray!(WorldObject, 1<<15);
class WorldObject { class WorldObject {
public Vec2f position; public Vec2f position;
public Rectf hitbox; public Rectf hitbox;
void update(float deltaTime); abstract void update(float deltaTime);
void render(float deltaTime); abstract void render(float deltaTime);
} }