wooo stuff yay

This commit is contained in:
kin fuyuki 2026-02-20 02:29:05 -03:00
commit d1bb9d8c67
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
91 changed files with 17403 additions and 42 deletions

View file

@ -1,39 +1,27 @@
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_FLAGS "-std=c++17 -Wno-error")
set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -w")
if (DEFINED PLATFORMNAME)
SET(CURRPLATFORM ${PLATFORMNAME})
else ()
SET(CURRPLATFORM "linux-64")
endif (DEFINED PLATFORMNAME)
file(GLOB_RECURSE ENGINE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/force_rebuild"
COMMAND rm -f "${CMAKE_SOURCE_DIR}/link/libenginend.so"
COMMAND rm -rf "${CMAKE_SOURCE_DIR}/include/enginend"
)
add_library(enginend SHARED ${ENGINE_SOURCES} "${CMAKE_BINARY_DIR}/force_rebuild"
../include/json.h)
add_library(enginend SHARED ${ENGINE_SOURCES} )
target_link_directories(
enginend PUBLIC
"${CMAKE_SOURCE_DIR}/link")
"${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}")
set(ENGINE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(ENGINE_EXPORT_DIR "${CMAKE_SOURCE_DIR}/include/enginend")
set_target_properties(enginend PROPERTIES
CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link"
CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}"
)
file(GLOB_RECURSE HEADER_FILES CONFIGURE_DEPENDS "${ENGINE_SRC_DIR}/*.h" "${ENGINE_SRC_DIR}/*.hpp")
foreach(HEADER ${HEADER_FILES})
file(RELATIVE_PATH REL_PATH "${ENGINE_SRC_DIR}" "${HEADER}")
set(DEST "${ENGINE_EXPORT_DIR}/${REL_PATH}")
get_filename_component(DEST_DIR "${DEST}" DIRECTORY)
add_custom_command(
TARGET enginend PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${HEADER}" "${DEST}"
)
endforeach()
add_executable(test test.cpp)
@ -43,9 +31,10 @@ set_target_properties(test PROPERTIES
)
target_link_directories(
test PUBLIC
"${CMAKE_SOURCE_DIR}/link")
"${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}")
target_link_libraries(test PRIVATE
"${CMAKE_SOURCE_DIR}/link/libenginend.so"
#"${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}/libenginend.so"
enginend
)
target_include_directories(test PUBLIC
${CMAKE_SOURCE_DIR}/include

0
engine/src/aud.h Normal file
View file

1
engine/src/engine.cpp Normal file
View file

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

14
engine/src/engine.h Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include "net.h"
#include "gr.h"
#include "aud.h"
#include "program.h"
#include "scenes/scene.h"
enum PLATFORM {
WINDOWS,LINUX,MACOS,
ANDROID,IOS
};
extern PLATFORM platform;
extern std::string androidpackage;
#include "resmgr.h"

2
engine/src/gr.h Normal file
View file

@ -0,0 +1,2 @@
#include "graph/window.h"

View file

@ -0,0 +1 @@
#include <raylib/raylib.h>

0
engine/src/net.h Normal file
View file

17
engine/src/program.cpp Normal file
View file

@ -0,0 +1,17 @@
#include "program.h"
long long calibrate() {
unsigned long long start = __rdtsc();
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 100000000L; // 0.1 seconds
nanosleep(&ts, NULL);
return (__rdtsc() - start) * 10;
}
const long long enginend::CPUCLOCK=calibrate();
void enginend::program::changescene(scene *scn) {
this->currentscene->exit();
delete this->currentscene;
this->currentscene = scn;
this->currentscene->boot();
}

46
engine/src/program.h Normal file
View file

@ -0,0 +1,46 @@
#pragma once
#define CFG this->CONF()
#include <immintrin.h>
#include <time.h>
#include "scenes/scene.h"
namespace enginend{
extern const long long CPUCLOCK;
inline const char* COMMONCONFIG();
class program {
unsigned long long currenttick = __rdtsc();
unsigned long long currentframe = __rdtsc();
public:
scene *currentscene;
int tickrate;
int framerate;
void changescene(scene*scn);
program():client(false){}
program(bool isclient):client(isclient){}
virtual const char* CONF()=0;
const bool client;
virtual void boot()=0;
virtual void tick()=0;
virtual void draw()=0;
virtual void exit()=0;
bool shouldtick() {
unsigned long long now = __rdtsc();
unsigned long long interval = CPUCLOCK / tickrate;
if (now - currenttick >= interval) {
currenttick = now;
return true;
}
return false;
}
bool shoulddraw() {
unsigned long long now = __rdtsc();
unsigned long long interval = CPUCLOCK / framerate;
if (now - currentframe >= interval) {
currentframe = now;
return true;
}
return false;
}
};}

12
engine/src/resmgr.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <string>
#include "engine.h"
inline const char *AT(std::string path) {
if (platform==LINUX || platform==WINDOWS || platform==MACOS) {
return path.c_str();
}else {
if (platform==ANDROID) {
return ("/data/data/"+androidpackage+"/files/"+path).c_str();
}
}
}

View file

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <functional>
#include "nodes.h"
namespace enginend {
@ -25,7 +25,7 @@ namespace enginend {
}
void boot()override{}
void tick()override{}
void draw()override{if(texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,WHITE);}
void draw()override{if(texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,rl::WHITE);}
void exit()override{delete texture;}
};
struct animated : virtual public textured {
@ -153,7 +153,7 @@ namespace enginend {
std::function<void()> func;
bool pressed;
bool hover;
final bool isboolean;
const bool isboolean;
button():pressed(false),isboolean(false){}
button(Texture2D* texture,Color color,float x,float y,float w,float h,std::function<void()> f):func(f),pressed(false),isboolean(false){
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;
@ -227,7 +227,7 @@ namespace enginend {
}
}
void draw()override{
DrawRectangle(pos.x,pos.y,size.x,size.y,DARKGRAY);
DrawRectangle(pos.x,pos.y,size.x,size.y,rl::DARKGRAY);
float t=(val-minv)/(maxv-minv);
DrawRectangle(pos.x,pos.y,size.x*t,size.y,c);
}
@ -333,7 +333,7 @@ namespace enginend {
line+=ch;
}
}
DrawRectangle(p.x+MeasureText(line.c_str(),fs),p.y,2,fs,BLACK);
DrawRectangle(p.x+MeasureText(line.c_str(),fs),p.y,2,fs,rl::BLACK);
}
}
void exit()override{this->textfield::exit();}

View file

@ -0,0 +1,423 @@
#pragma once
#include <string>
#include "nodes.h"
#include <raylib/raylib.h>
namespace enginend{
namespace nodes{
namespace relative {
struct node2d :public node {
double x;
double y;
double w;
double h;
node2d(){x=0;y=0;w=0;h=0;}
node2d(double x,double y,double w=0,double h=0):x(x),y(y),w(w),h(h){}
};
struct rect :virtual public node2d{
rect(){}
rect(double x,double y,double w,double h):node2d(x,y,w,h){}
};
struct textured :virtual public rect{
Texture2D* texture;
textured(){texture=nullptr;}
textured(Texture2D* texture,double x,double y,double w,double h):texture(texture),rect(x,y,w,h){}
void boot() override{}
void tick() override{}
void draw()override{
if(texture==nullptr)return;
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
tiny::echo("og: %f %f %f %f", x,y,w,h);
tiny::echo("transformed: %f %f %f %f", ax, ay, aw, ah);
DrawTexturePro(*texture,{0,0,(float)texture->width,(float)texture->height},{ax,ay,aw,ah},{0,0},0,rl::WHITE);
}
void exit()override {
if(texture){
UnloadTexture(*texture);
delete texture;
texture=nullptr;
}
}
};
struct animated :virtual public textured{
Image animimage;
int frames;
int currentframe;
int framedelay;
int framecounter;
int prevframe;
unsigned int nextframeoffset;
animated():frames(0),currentframe(1),framedelay(6),framecounter(0),nextframeoffset(0){
animimage.data=nullptr;
prevframe=currentframe;
}
animated(const char* gifpath,double x,double y,double w,double h,int delay=6):
textured(nullptr,x,y,w,h),framedelay(delay),currentframe(1),framecounter(0),frames(0),nextframeoffset(0)
{
prevframe=currentframe;
this->x=x; this->y=y; this->w=w; this->h=h;
animimage=LoadImageAnim(gifpath,&frames);
if(frames>0){
texture=new Texture2D(LoadTextureFromImage(animimage));
}
}
void tick()override{
if(frames<=1)return;
framecounter++;
if(framecounter>=framedelay){
framecounter=0;
currentframe++;
if(currentframe>=frames)currentframe=0;
nextframeoffset=animimage.width*animimage.height*4*currentframe;
tiny::echo("updating node\nframes: %i\n current frame: %i",frames,currentframe);
tiny::echo("%i",nextframeoffset);
}
}
void draw()override {
if (prevframe!=currentframe){
prevframe=currentframe;
UpdateTexture(*this->texture,((unsigned char*)animimage.data)+nextframeoffset);
}
textured::draw();
}
void exit()override{
if(animimage.data)UnloadImage(animimage);
textured::exit();
}
};
struct colored :virtual public rect{
Color c;
colored(){}
colored(Color color,double x,double y,double w,double h):c(color),rect(x,y,w,h){}
void boot()override{}
void tick()override{}
void draw()override{
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
DrawRectangle(ax,ay,aw,ah,c);
}
void exit()override{}
};
struct tinted :virtual public colored,virtual public textured{
tinted(){}
tinted(Texture2D* texture,Color color,double x,double y,double w,double h):
node2d(x,y,w,h),
rect(x,y,w,h),
colored(color,x,y,w,h),
textured(texture,x,y,w,h)
{}
void boot()override{}
void tick()override{}
void draw()override{
if(texture==nullptr)return;
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
DrawTexturePro(*texture,{0,0,(float)texture->width,(float)texture->height},{ax,ay,aw,ah},{0,0},0,c);
}
void exit()override{
textured::exit();
}
};
struct text :public tinted {
protected:
std::string result;
public:
Font font;
float fs;
Color txc;
std::string content;
text(){fs=20;}
text(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt):
//tinted(texture,color,x,y,w,h),
font(f),fs(fsize),content(txt),txc(txcol)
{
this->x=x;this->y=y;this->w=w;this->h=h;
this->texture=texture;this->c=color;
result=content;
size_t initp=0;
while((initp=result.find("\n",initp))!=std::string::npos){
result.replace(initp,1,"\\n");
initp+=2;
}
}
void boot()override{}
void tick()override {
if(result!=content){
result=content;
size_t initp=0;
while((initp=result.find("\n",initp))!=std::string::npos){
result.replace(initp,1,"\\n");
initp+=2;
}
}
}
void draw()override {
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
tiny::echo("og: %f %f %f %f", x,y,w,h);
tiny::echo("drawing text: %s", content.c_str());
tiny::echo("transformed: %f %f %f %f", ax, ay, aw, ah);
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,1);
Vector2 charsize=MeasureTextEx(font," ",fs,1);
float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y;
p=p*2;
int minh=(minsize.y>ah)?minsize.y:ah;
int minw=(minsize.x>aw)?minsize.x:aw;
DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,c);
DrawTextEx(font,content.c_str(),{ax,ay},fs,1,txc);
}
void exit()override{
tinted::exit();
}
};
struct button :virtual public tinted{
void(*func)();
bool pressed;
bool hover;
button():func(nullptr),pressed(false),hover(false){}
button(Texture2D* texture,Color color,double x,double y,double w,double h,void(*f)()):func(f),pressed(false),hover(false),tinted(texture,color,x,y,w,h){}
void boot()override{}
void tick()override{
Vector2 mouse=GetMousePosition();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
Rectangle r={float(x*sw),float(y*sh),float(w*sw),float(h*sh)};
if(CheckCollisionPointRec(mouse,r)){hover=true;
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
pressed=true;
if(func)func();
}else{
pressed=false;
}
}else{
hover=false;
pressed=false;
}
}
void draw()override {
tinted::draw();
}
void exit()override{
tinted::exit();
}
};
struct labeledbutton :virtual public button {
std::string label;
Font font;
int fs;
Color txc;
labeledbutton(std::string name,Texture2D* texture,Color color,Color text,
double x,double y,double w,double h,void(*f)(),
Font fnt,int size):font(fnt),fs(size),txc(text),label(name),
button(texture,color,x,y,w,h,f)
{}
void boot()override{}
void tick()override{
button::tick();
}
void draw()override{
button::draw();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
Vector2 tsize=MeasureTextEx(font,label.c_str(),fs,1);
Vector2 tpos={
ax+(aw-tsize.x)/2,
ay+(ah-tsize.y)/2
};
DrawTextEx(font,label.c_str(),tpos,fs,1,txc);
}
void exit()override{
button::exit();
}
};
struct slider :virtual public tinted{
float val;
float minv;
float maxv;
slider():val(0),minv(0),maxv(1){}
slider(Texture2D* texture,Color color,double x,double y,double w,double h,float min,float max,float v):val(v),minv(min),maxv(max),tinted(texture,color,x,y,w,h){}
void boot()override{}
void tick()override{
Vector2 mouse=GetMousePosition();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
Rectangle r={float(x*sw),float(y*sh),float(w*sw),float(h*sh)};
if(CheckCollisionPointRec(mouse,r)&&IsMouseButtonDown(MOUSE_LEFT_BUTTON)){
float t=(mouse.x-(x*sw))/(w*sw);
val=minv+t*(maxv-minv);
if(val<minv)val=minv;
if(val>maxv)val=maxv;
}
}
void draw()override{
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
DrawRectangle(ax,ay,aw,ah,rl::DARKGRAY);
float t=(val-minv)/(maxv-minv);
DrawRectangle(ax,ay,aw*t,ah,c);
}
void exit()override{
tinted::exit();
}
};
struct textfield :public text{
textfield(){}
textfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt):
text(texture,txcol,color,x,y,w,h,f,fsize,txt){}
void boot()override{}
void tick()override{
text::tick();
}
void draw()override{
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
Vector2 charsize=MeasureTextEx(font," ",fs,0);
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,charsize.x/2);
float po=charsize.x>charsize.y?charsize.x/charsize.y:charsize.y/charsize.x;po=po*5;
int minh=(minsize.y>ah)?minsize.y:ah;
int minw=(minsize.x>aw)?minsize.x:aw;
DrawRectangle(ax-(po/2),ay-(po/2),minw+(po*1.1),minh+(po*1.1),c);
DrawTextEx(font,content.c_str(),{ax,ay},fs,charsize.x/2,txc);
}
void exit()override{
text::exit();
}
};
struct textinput :public text{
bool active;
int cpos;
textinput():active(false),cpos(0){}
textinput(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0),
text(texture,txcol,color,x,y,w,h,f,fsize,""){}
void boot()override{}
void tick()override{
text::tick();
Vector2 mouse=GetMousePosition();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
Rectangle r={float(x*sw),float(y*sh),float(w*sw),float(h*sh)};
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
active=CheckCollisionPointRec(mouse,r);
}
if(active){
int key=GetCharPressed();
while(key>0){
if(key>=32&&key<=125){
content+=static_cast<char>(key);
cpos++;
}
key=GetCharPressed();
}
if(IsKeyPressed(KEY_BACKSPACE)&&content.length()>0){
content.pop_back();
cpos--;
}
}
}
void draw()override{
text::draw();
if(active){
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
DrawRectangle(ax+MeasureTextEx(font,content.c_str(),fs,1).x,ay,2,fs,{0,0,0,127});
}
}
void exit()override{
text::exit();
}
};
struct textinputfield :public textfield{
bool active;
int cpos;
textinputfield():active(false),cpos(0){}
textinputfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0),
textfield(texture,txcol,color,x,y,w,h,f,fsize,""){}
void boot()override{}
void tick()override{
textfield::tick();
Vector2 mouse=GetMousePosition();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
Rectangle r={float(x*sw),float(y*sh),float(w*sw),float(h*sh)};
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
active=CheckCollisionPointRec(mouse,r);
}
if(active){
int key=GetCharPressed();
while(key>0){
if(key>=32&&key<=125){
content+=static_cast<char>(key);
cpos++;
}
key=GetCharPressed();
}
if(IsKeyPressed(KEY_BACKSPACE)&&content.length()>0){
content.pop_back();
cpos--;
}
if(IsKeyPressed(KEY_ENTER)){
content+='\n';
cpos++;
}
}
}
void draw()override{
textfield::draw();
if(active){
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
float ay=y*sh;
float lh=fs+2;
Vector2 p={ax,ay};
std::string line="";
for(char ch:content){
if(ch=='\n'){
p.y+=lh;
line="";
}else{
line+=ch;
}
}
DrawRectangle(p.x+MeasureTextEx(font,line.c_str(),fs,1).x,p.y,2,fs,rl::BLACK);
}
}
void exit()override{
textfield::exit();
}
};
}
}
}

40
engine/src/scenes/scene.h Normal file
View file

@ -0,0 +1,40 @@
#pragma once
#include "nodes.h"
#include "node2d.h"
#include "node2drelative.h"
#include <list>
namespace enginend {
struct scene{
std::list<enginend::nodes::node*> nodes;
virtual void boot() {
int i=0;
tiny::echo((char*)"initializing scene");
for (enginend::nodes::node* n : nodes) {
tiny::echo((char*)"initializing object of ID: %i",i++);
n->boot();
}
}
virtual void draw() {
ClearBackground(rl::BLANK);
BeginDrawing();
for (enginend::nodes::node* n : nodes) {
n->draw();
}
EndDrawing();
}
virtual void tick() {
for (enginend::nodes::node* n : nodes) {
n->tick();
}
}
virtual void exit() {
for (enginend::nodes::node* n : nodes) {
n->exit();
}
}
};
}

52
engine/test.cpp Normal file
View file

@ -0,0 +1,52 @@
#include <enginend/engine.h>
using namespace enginend;
class launcher:public program {
public:
bool vsync = true;
scene s;
const char* CONF() final{return "test.tdf";}
launcher(){};
void boot() override {
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(500,500,"test");
SetTargetFPS(GetMonitorRefreshRate(GetCurrentMonitor()));
this->tickrate=GetMonitorRefreshRate(GetCurrentMonitor());
s.nodes=std::list<nodes::node*>{
new nodes::colored(Color{255,255,255,255},0,0,500,500),
new nodes::textfield(nullptr,Color{255,127,127,255},Color{127,127,127,255}
,100,100,220,32,GetFontDefault(),32,
"welcome to enginend!\n"
"hehe"
)
};
s.boot();
}
void tick() override {
if (shouldtick()) {
s.tick();
}
}
void draw() override {
s.draw();
}
void exit() override {
s.exit();
}
};
tiny::ErrorLevel tiny::level{6};
int main(int argc, char *argv[]) {
tiny::startup((char*)"enginend test",(char*)"1.0");
launcher e;
e.boot();
while (!WindowShouldClose()) {
e.tick();
e.draw();
}
e.exit();
return 0;
}