starting the rewrite of forespend.

This commit is contained in:
kin fuyuki 2025-12-25 13:21:58 -03:00
commit d36dc68f8a
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
19 changed files with 833 additions and 290 deletions

View file

@ -1,9 +1,35 @@
#include "client.h"
client::client(){}
void client::boot() {}
void client::draw() {}
void client::exit() {}
void client::tick() {}
#include "scenes/mainmenu.h"
client::client() {
}
void client::boot() {
this->framerate=60;
this->tickrate=20;
InitWindow(380,240,"forespend - 0.03h");
// SetConfigFlags();
this->currentscene=new mainmenu();
this->currentscene->boot();
target=LoadRenderTexture(380,240);
}
void client::draw() {
BeginTextureMode(target);
this->currentscene->draw();
EndTextureMode();
BeginDrawing();
ClearBackground(WHITE);
DrawTexturePro(target.texture, {0, 0, 380,240}, {0, 0, (float)GetScreenWidth(), (float)GetScreenHeight()}, {0, 0}, 0, WHITE);
EndDrawing();
}
void client::exit() {
this->currentscene->exit();
delete this->currentscene;
}
void client::tick() {
this->currentscene->tick();
}

View file

@ -1,9 +1,10 @@
#pragma once
#include <incmgr.h>
class client :public program{
class client :public enginend::program{
public:
RenderTexture2D target;
const char* CONF() final{return "client.tdf";}
client();
void boot() override;

View file

@ -0,0 +1 @@
#include "game.h"

View file

@ -0,0 +1,7 @@
#pragma once
#include <incmgr.h>
class game :public virtual enginend::scene {
};

View file

@ -1 +1 @@
#include "mainmenu.h"
#include "mainmenu.h"

View file

@ -1,6 +1,22 @@
#pragma once
#include <incmgr.h>
#include <enginend/scenes/node2drelative.h>
class mainmenu :public virtual scene{
class mainmenu :public virtual enginend::scene{
public:
void boot() override {
this->nodes=std::list<enginend::nodes::node*>{
new enginend::nodes::relative::animated(AT("res/images/sky.gif"),0,0,10,10,5)
};
enginend::scene::boot();
}
void tick() override {
enginend::scene::tick();
}
void draw() override {
enginend::scene::draw();
}
void exit() override {
enginend::scene::exit();
}
};

View file

@ -1,11 +1,57 @@
#include <atomic>
#include <incmgr.h>
#include <thread>
#include "server/server.h"
#include "client/client.h"
PLATFORM platform=LINUX;
std::string androidpackage="kn.kinfuyuki.forespend";
inline const char* COMMONCONFIG(){return "common.tdf";}
tiny::ErrorLevel tiny::level{6};
int main(int argc, char** argv) {
enginend::program* game;
tiny::startup("forespend","0.03g-rewrite");
bool isserver = false;
if (argc>1) {
for (int i=1;i<argc;i++) {
if (argv[i]=="server") {
isserver = true;
}
}
}
if (isserver) game = new server();else game = new client();
game->boot();
std::atomic<bool> running{true};
std::thread tickthread([game, &running]() {
double tickrate=1.0/game->tickrate;
auto lasttick=std::chrono::high_resolution_clock::now();
while (running) {
auto now=std::chrono::high_resolution_clock::now();
double elapsed=std::chrono::duration_cast<std::chrono::duration<double>>(now-lasttick).count();
if (elapsed>=tickrate) {
game->tick();
lasttick=now;
} else {
std::this_thread::sleep_for(std::chrono::duration<double>(tickrate-elapsed));
}
}
});
double framerate=1.0/game->framerate;
auto lastframe=std::chrono::high_resolution_clock::now();
while (!WindowShouldClose()) {
auto now=std::chrono::high_resolution_clock::now();
double elapsed=std::chrono::duration_cast<std::chrono::duration<double>>(now-lastframe).count();
if (elapsed>=framerate) {
game->draw();
lastframe=now;
} else {
WaitTime(framerate-elapsed);
}
}
game->exit();
return 0;
}

View file

@ -2,7 +2,7 @@
#include <incmgr.h>
class server : public program{
class server : public enginend::program{
public:
server();
const char* CONF() final{return "client.tdf";}