made tons of stuff lol

This commit is contained in:
kin fuyuki 2025-12-21 03:01:29 -03:00
commit 54c3acf092
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
16 changed files with 450 additions and 94 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(games)
SET(CMAKE_CXX_FLAGS "-std=c++23")
set(CMAKE_CXX_FLAGS "-std=c++17 -Wno-error")
if(WIN32)
set(PLATFORM_DIR "windows")
else()

View file

@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.20)
SET(CMAKE_CXX_FLAGS "-std=c++23 -Werror")
file(GLOB_RECURSE ENGINE_SOURCES "src/*.cpp")
add_library(enginend SHARED ${ENGINE_SOURCES})
target_include_directories(enginend PUBLIC
${CMAKE_SOURCE_DIR}/include
set(CMAKE_CXX_FLAGS "-std=c++17 -Wno-error")
file(GLOB_RECURSE ENGINE_SOURCES "${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")
target_link_directories(
enginend PUBLIC
"${CMAKE_SOURCE_DIR}/link")
@ -32,4 +31,26 @@ foreach(HEADER ${HEADER_FILES})
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${HEADER}" "${DEST}"
)
endforeach()
endforeach()
add_executable(test test.cpp)
set_target_properties(test PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/engine/test"
)
target_link_directories(
test PUBLIC
"${CMAKE_SOURCE_DIR}/link")
target_link_libraries(test PRIVATE
"${CMAKE_SOURCE_DIR}/link/libenginend.so"
"${CMAKE_SOURCE_DIR}/link/libdesktopraylib.so"
)
target_include_directories(test PUBLIC
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/lib/raylib/build/raylib/include
)
target_include_directories(enginend PUBLIC
${CMAKE_SOURCE_DIR}/lib/raylib/build/raylib/include
)

View file

@ -1,4 +1,5 @@
#include "net.h"
#include "gr.h"
#include "aud.h"
#include "program.h"
#include "program.h"
#include "scenes/scene.h"

View file

@ -1,2 +1,2 @@
#include <raylib.h>
#include "graph/window.h"

View file

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

View file

@ -1 +1,11 @@
#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();

View file

@ -1,8 +1,17 @@
#pragma once
#define CFG this->CONF()
#include <immintrin.h>
#include <time.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:
int tickrate;
int framerate;
program():client(false){}
program(bool isclient):client(isclient){}
virtual const char* CONF()=0;
@ -11,4 +20,23 @@ public:
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;
}
};}

View file

@ -1,44 +1,251 @@
#include "nodes.h"
#pragma once
#include <string>
struct node2d :public node {
vec2 pos;
node2d(){}
node2d(float x,float y):pos(x,y){}
};
struct rect :virtual public node2d{
vec2 size;
rect(){}
rect(float x,float y,float w, float h):size(w,h){
this->pos=vec2(x,y);
}
};
struct textured :virtual public rect{
int ID;
textured(){}
textured(int id,float x,float y,float w, float h):ID(id){
this->pos=vec2(x,y);this->size=vec2(w,h);
}
};
struct colored :virtual public rect{
col c;
colored(){}
colored(col color,float x,float y,float w, float h):c(color){
this->pos=vec2(x,y);this->size=vec2(w,h);
}
};
struct tinted :virtual public colored, virtual public textured{
tinted(){}
tinted(int id,col color,float x,float y,float w, float h):
node2d(x, y),
rect(x, y, w, h),
colored(color, x, y, w, h),
textured(id, x, y, w, h)
{
}
};
struct text :virtual tinted {
Font font;
std::string text;
};
#include "nodes.h"
#include<tiny/term.h>
namespace enginend {
struct node2d :public node {
Vector2 pos;
node2d(){}
node2d(float x,float y):pos(Vector2{x,y}){}
};
struct rect :virtual public node2d{
Vector2 size;
rect(){}
rect(float x,float y,float w, float h):size(Vector2{w,h}){
this->pos=Vector2{x,y};
}
};
struct textured :virtual public rect{
int ID;
textured(){}
textured(int id,float x,float y,float w, float h):ID(id){
this->pos=Vector2{x,y};this->size=Vector2{w,h};
}
void boot()override{}
void tick()override{}
void draw()override{DrawTexture(LoadTexture(""),pos.x,pos.y,WHITE);}
void exit()override{}
};
struct colored :virtual public rect{
Color c;
colored(){}
colored(Color color,float x,float y,float w, float h):c(color){
this->pos=Vector2{x,y};this->size=Vector2{w,h};
}
void boot()override{}
void tick()override{}
void draw()override{DrawRectangle(pos.x,pos.y,size.x,size.y,c);}
void exit()override{}
};
struct tinted :virtual public colored, virtual public textured{
tinted(){}
tinted(int id,Color color,float x,float y,float w, float h):
node2d(x, y),
rect(x, y, w, h),
colored(color, x, y, w, h),
textured(id, x, y, w, h)
{}
void boot()override{this->colored::boot();this->textured::boot();}
void tick()override{this->colored::tick();this->textured::tick();}
void draw()override{DrawTexture(LoadTexture(""),pos.x,pos.y,c);}
void exit()override{this->colored::exit();this->textured::exit();}
};
struct text :public tinted {
protected:
std::string result;
public:
Font font;
float fontsize;
Color textcolor;
std::string content;
text(){ fontsize = 20; }
text(int id,Color textcol,Color color,float x,float y,float w,float h,Font f,float fs,std::string txt):
font(f),fontsize(fs),content(txt)
{
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->ID=id;this->c=color;this->textcolor=textcol;
result=content;
size_t initpos = 0;
while((initpos = result.find("\n", initpos)) != std::string::npos) {
result.replace(initpos, 1, "\\n");
initpos += 2;
}
}
void boot()override{this->tinted::boot();}
void tick()override {
this->tinted::tick();
if (result!=content) {
result=content;
size_t initpos = 0;
while((initpos = result.find("\n", initpos)) != std::string::npos) {
result.replace(initpos, 1, "\\n");
initpos += 2;
}
}
}
void draw()override {
Vector2 minsize=MeasureTextEx(font, content.c_str(), fontsize, 1);
Vector2 charsize=MeasureTextEx(font, " ", fontsize, 1);
float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y;
p=p*2;
int minh=(minsize.y>size.y)?minsize.y:size.y;
int minw=(minsize.x>size.x)?minsize.x:size.x;
DrawRectangle(pos.x-charsize.x,pos.y-charsize.y,minw+p,minh+p,c);
DrawTextEx(font, content.c_str(), pos, fontsize, 1, textcolor);
}
void exit()override{this->tinted::exit();}
};
struct button :virtual public tinted{
std::function<void()> function;
bool pressed;
button():pressed(false){}
button(int id,Color color,float x,float y,float w,float h,std::function<void()> func):function(func),pressed(false){
this->pos=Vector2{x,y};this->size=Vector2{x,y};this->ID=id;this->c=color;
}
void boot()override{this->tinted::boot();}
void tick()override{
this->tinted::tick();
Vector2 mouse=GetMousePosition();
if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})&&IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(function)function();
}
}
void draw()override{DrawRectangle(pos.x,pos.y,size.x,size.y,c);}
void exit()override{this->tinted::exit();}
};
struct slider :virtual public tinted{
float value;
float minvalue;
float maxvalue;
slider():value(0),minvalue(0),maxvalue(1){}
slider(int id,Color color,float x,float y,float w,float h,float min,float max,float val):value(val),minvalue(min),maxvalue(max){
this->pos=Vector2{x,y};this->size=Vector2{x,y};this->ID=id;this->c=color;
}
void boot()override{this->tinted::boot();}
void tick()override{
this->tinted::tick();
Vector2 mouse=GetMousePosition();
if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})&&IsMouseButtonDown(MOUSE_LEFT_BUTTON)){
float t=(mouse.x-pos.x)/size.x;
value=minvalue+t*(maxvalue-minvalue);
if(value<minvalue)value=minvalue;
if(value>maxvalue)value=maxvalue;
}
}
void draw()override{
DrawRectangle(pos.x,pos.y,size.x,size.y,DARKGRAY);
float t=(value-minvalue)/(maxvalue-minvalue);
DrawRectangle(pos.x,pos.y,size.x*t,size.y,c);
}
void exit()override{this->tinted::exit();}
};
struct textfield :public text{
textfield(){}
textfield(int id,Color textcol,Color color,float x,float y,float w,float h,Font f,float fs,std::string txt):
text(id,textcol,color,x,y,w,h,f,fs,txt){}
void boot()override{this->text::boot();}
void tick()override{this->text::tick();}
void draw()override{
Vector2 p=pos;
float lineheight=fontsize+2;
std::string line="";
Vector2 charsize=MeasureTextEx(font, " ", fontsize, 0);
Vector2 minsize=MeasureTextEx(font, content.c_str(), fontsize, charsize.x/2);
float po=charsize.x>charsize.y?charsize.x/charsize.y:charsize.y/charsize.x;po=po*5;
int minh=(minsize.y>size.y)?minsize.y:size.y;
int minw=(minsize.x>size.x)?minsize.x:size.x;
DrawRectangle(pos.x-(po/2),pos.y-(po/2),minw+(po*1.1),minh+(po*1.1),c);
DrawTextEx(font,content.c_str(),p,fontsize,charsize.x/2,this->textcolor);
}
void exit()override{this->text::exit();}
};
struct textinput :public text{
bool active;
int cursorpos;
textinput():active(false),cursorpos(0){}
textinput(int id,Color textcol,Color color,float x,float y,float w,float h,Font f,float fs):active(false),cursorpos(0){
this->pos=Vector2{x,y};this->size=Vector2{x,y};this->ID=id;this->c=color;this->font=f;this->content="";
this->textcolor=textcol;this->fontsize=fs;
}
void boot()override{this->text::boot();}
void tick()override{
this->text::tick();
Vector2 mouse=GetMousePosition();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
active=CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y});
}
if(active){
int key=GetCharPressed();
while(key>0){
if(key>=32&&key<=125){
content+=static_cast<char>(key);
cursorpos++;
}
key=GetCharPressed();
}
if(IsKeyPressed(KEY_BACKSPACE)&&content.length()>0){
content.pop_back();
cursorpos--;
}
}
}
void draw()override{
this->text::draw();
if(active)DrawRectangle(pos.x+MeasureText(content.c_str(),fontsize),pos.y,2,fontsize,{0,0,0,127});
}
void exit()override{this->text::exit();}
};
struct textinputfield :public textfield{
bool active;
int cursorpos;
textinputfield():active(false),cursorpos(0){}
textinputfield(int id,Color textcol,Color color,float x,float y,float w,float h,Font f,float fs):active(false),cursorpos(0),
textfield(id,textcol,color,x,y,w,h,f,fs,""){}
void boot()override{this->textfield::boot();}
void tick()override{
this->textfield::tick();
Vector2 mouse=GetMousePosition();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
active=CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y});
}
if(active){
int key=GetCharPressed();
while(key>0){
if(key>=32&&key<=125){
content+=static_cast<char>(key);
cursorpos++;
}
key=GetCharPressed();
}
if(IsKeyPressed(KEY_BACKSPACE)&&content.length()>0){
content.pop_back();
cursorpos--;
}
if(IsKeyPressed(KEY_ENTER)){
content+='\n';
cursorpos++;
}
}
}
void draw()override{
this->textfield::draw();
if(active){
Vector2 p=pos;
float lineheight=fontsize+2;
std::string line="";
for(char ch:content){
if(ch=='\n'){
p.y+=lineheight;
line="";
}else{
line+=ch;
}
}
DrawRectangle(p.x+MeasureText(line.c_str(),fontsize),p.y,2,fontsize,BLACK);
}
}
void exit()override{this->textfield::exit();}
};
}

View file

@ -1,11 +1,15 @@
#pragma once
#include "../gr.h"
#include "../aud.h"
#include "../net.h"
struct node{
public:
namespace enginend {
struct node{
public:
virtual void init() {}
virtual void render() {}
virtual void update() {}
virtual void close() {}
};
virtual void boot()=0;
virtual void tick()=0;
virtual void draw()=0;
virtual void exit()=0;
};
}

View file

@ -1,9 +1,31 @@
#include "nodes.h"
#include <list>
struct scene{
std::list<node> nodes;
virtual void init() {}
virtual void render() {}
virtual void update() {}
virtual void close() {}
};
namespace enginend {
struct scene{
std::list<enginend::node*> nodes;
virtual void boot() {
for (enginend::node* n : nodes) {
n->boot();
}
}
virtual void draw() {
BeginDrawing();
for (enginend::node* n : nodes) {
n->draw();
}
EndDrawing();
}
virtual void tick() {
for (enginend::node* n : nodes) {
n->tick();
}
}
virtual void exit() {
for (enginend::node* n : nodes) {
n->exit();
}
}
};
}

53
engine/test.cpp Normal file
View file

@ -0,0 +1,53 @@
#include <incmgr.h>
#include <raylib.h>
#include <enginend/scenes/node2d.h>
using namespace enginend;
class test:public program {
public:
bool vsync = true;
scene s;
const char* CONF() final{return "test.tdf";}
test(){};
void boot() override {
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(500,500,"test");
SetTargetFPS(GetMonitorRefreshRate(GetCurrentMonitor()));
this->tickrate=GetMonitorRefreshRate(GetCurrentMonitor());
s.nodes=std::list<node*>{
new colored(Color{255,255,255,255},0,0,500,500),
new textfield(0,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");
test e;
e.boot();
while (!WindowShouldClose()) {
e.tick();
e.draw();
}
e.exit();
return 0;
}

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
SET(CMAKE_CXX_FLAGS "-std=c++23")
set(CMAKE_CXX_FLAGS "-std=c++17 -Wno-error")
file(GLOB_RECURSE FORESPEND_SOURCES "src/*.cpp")
add_executable(forespend ${FORESPEND_SOURCES})

View file

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

View file

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

View file

@ -7,6 +7,7 @@
#include <fstream>
#include <stdexcept>
#include <vector>
#pragma GCC diagnostic ignored "-Wdelete-incomplete"
#ifndef TINYDATAFORMAT_H
#define TINYDATAFORMAT_H
#define TINYDEFINEHEADER "0000_TDF_HEADER_DEFINE"

View file

@ -1,4 +1,5 @@
#pragma once
#pragma GCC diagnostic ignored "-Wvarargs"
#ifndef TINYTERM_H
#define TINYTERM_H
@ -37,24 +38,24 @@ tiny::ErrorLevel tiny::level={1};
extern tiny::ErrorLevel level;
#define WHITE "\033[0m" /* White */
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BGRED "\033[41m" /* Red */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
const char* WHITE="\033[0m";
const char* BLACK="\033[30m";
const char* RED="\033[31m";
const char* GREEN="\033[32m";
const char* YELLOW="\033[33m";
const char* BLUE="\033[34m";
const char* MAGENTA="\033[35m";
const char* CYAN="\033[36m";
const char* BGRED="\033[41m";
const char* BOLDBLACK="\033[1m\033[30m";
const char* BOLDRED="\033[1m\033[31m";
const char* BOLDGREEN="\033[1m\033[32m";
const char* BOLDYELLOW="\033[1m\033[33m";
const char* BOLDBLUE="\033[1m\033[34m";
const char* BOLDMAGENTA="\033[1m\033[35m";
const char* BOLDCYAN="\033[1m\033[36m";
const char* BOLDWHITE="\033[1m\033[37m";
#define ending \
mixer.append(info); mixer.append("\033[0m\n");\
const char * finalinfo=mixer.c_str();\
@ -62,7 +63,7 @@ extern tiny::ErrorLevel level;
vfprintf (stdout, finalinfo, arg);\
va_end (arg);
inline void echo(char * info,...){
inline void echo(const char * info,...){
if (level.value==4)
{
va_list arg;
@ -73,36 +74,36 @@ inline void echo(char * info,...){
vfprintf (stdout, finalinfo, arg);
va_end (arg);}
}
inline void warning( char * info,...){
inline void warning(const char * info,...){
if (level.value>=1)
{
va_list arg;
std::string mixer=YELLOW;ending
}
}
inline void fatal( char * info,...){
inline void fatal(const char * info,...){
va_list arg;
std::string mixer=BOLDWHITE+std::string(BGRED);ending
}
inline void error( char * info,...){
inline void error(const char * info,...){
if (level.value>=0)
{
va_list arg;
std::string mixer=BOLDRED;ending
}}
inline void success(char * info , ...){
inline void success(const char * info , ...){
if (level.value>=2)
{
va_list arg;
std::string mixer=GREEN;ending}
}
inline void message(char * info , ...){
inline void message(const char * info , ...){
if (level.value>=3)
{
va_list arg;
std::string mixer=BOLDWHITE;ending}
}
inline void startup(char* game,char*version){
inline void startup(const char* game,const char*version){
int lv=level.value;level.value=6;
echo("%s %s",game,version);
warning("be warned that");