Update function names

This commit is contained in:
Fierelier 2023-05-14 17:48:31 +02:00
parent b1e828c0ca
commit 0201ffb6e6
6 changed files with 44 additions and 42 deletions

View File

@ -2,25 +2,27 @@ A software accelerated (CPU-only) game engine for older computers. It uses a lay
>>> FUNCTIONS
>> WINDOW
> void engine_init(int width,int height,char * title)
> void engine_setColor(char r,char g,char b,char a)
> void engine_drawPixel(int x,int y)
> void engine_render()
> void engine_window_init(int width,int height,char * title)
> void engine_window_present()
>> SURFACE
> void engine_surface_color_set(char r,char g,char b,char a)
> void engine_surface_draw_pixel(int x,int y)
>> TIME
> long long engine_time_get()
> void engine_sleep(long long ms)
> void engine_time_sleep(long long ms)
>> LOGIC
> struct ENGINE_EVENT engine_get_event()
> struct ENGINE_EVENT engine_event_get()
>> TEXTURES
struct ENGINE_TEXTURE engine_createTexture(int width,int height)
> void engine_textureSetColor(char r,char g,char b,char a)
> void engine_textureDrawPixel(struct ENGINE_TEXTURE * texture,int x,int y)
> void engine_textureDestroy(struct ENGINE_TEXTURE * texture)
> void engine_renderTexture2D(struct ENGINE_TEXTURE * texture,int sx,int sy)
> void engine_fileToTexture(struct ENGINE_TEXTURE * texture,char * fpath)
> void engine_texture_color_set(char r,char g,char b,char a)
> void engine_texture_draw_pixel(struct ENGINE_TEXTURE * texture,int x,int y)
> void engine_texture_destroy(struct ENGINE_TEXTURE * texture)
> void engine_texture_render_2d(struct ENGINE_TEXTURE * texture,int sx,int sy)
> void engine_texture_from_file(struct ENGINE_TEXTURE * texture,char * fpath)
>>> EVENTS
ENGINE_EVENT contains a char denoting the type (ENGINE_EVENT_TYPE_*), and a void * containing the content of the event data, which should be cast to one of the ENGINE_EVENT_* structs:

8
main.c
View File

@ -26,8 +26,8 @@ void tick() {
}
luaL_loadstring(engine_lua_state,"engine_onFrame()");
lua_call(engine_lua_state,0,0);
engine_render();
//engine_sleep(33);
engine_window_present();
//engine_time_sleep(33);
}
int main(int argc, char **argv) {
@ -35,11 +35,11 @@ int main(int argc, char **argv) {
printf("argv[%d]: %s\n", i, argv[i]);
}
engine_init(96,64,"Game");
engine_window_init(96,64,"Game");
engine_luaInit();
while (1) {
struct ENGINE_EVENT event = engine_getEvent();
struct ENGINE_EVENT event = engine_event_get();
if (event.type != ENGINE_EVENT_TYPE_NONE) {
handleEvent(event);
} else {

View File

@ -6,7 +6,7 @@ lua_State * engine_lua_state;
int engine_luafSleep(lua_State *L) {
int time = luaL_checkinteger(L,1);
engine_sleep(time);
engine_time_sleep(time);
return 0;
}
@ -20,7 +20,7 @@ int engine_luafLoadTexture(lua_State *L) {
int width = luaL_checkinteger(L,2);
int height = luaL_checkinteger(L,3);
struct ENGINE_TEXTURE * texture = engine_createTexture(width,height);
engine_fileToTexture(texture,fpath);
engine_texture_from_file(texture,fpath);
lua_pushlightuserdata(L,texture);
return 1;
}
@ -29,7 +29,7 @@ int engine_luafRenderTexture2D(lua_State *L) {
struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1);
int x = luaL_checkinteger(L,2);
int y = luaL_checkinteger(L,3);
engine_renderTexture2D(texture,x,y);
engine_texture_render_2d(texture,x,y);
return 0;
}

View File

@ -24,14 +24,14 @@ struct ENGINE_TEXTURE * engine_createTexture(int width,int height) {
struct ENGINE_GENERIC_TEXTURE_COLOR { char r; char g; char b; char a; };
struct ENGINE_GENERIC_TEXTURE_COLOR engine_generic_texture_color;
void engine_textureSetColor(char r,char g,char b,char a) {
void engine_texture_color_set(char r,char g,char b,char a) {
engine_generic_texture_color.r = r;
engine_generic_texture_color.g = g;
engine_generic_texture_color.b = b;
engine_generic_texture_color.a = a;
}
void engine_textureDrawPixel(struct ENGINE_TEXTURE * texture,int x,int y) {
void engine_texture_draw_pixel(struct ENGINE_TEXTURE * texture,int x,int y) {
char * pixels = ((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels;
long pixelIndex = (x + y * texture->width) * 4;
pixels[pixelIndex + 0] = engine_generic_texture_color.r;
@ -40,14 +40,14 @@ void engine_textureDrawPixel(struct ENGINE_TEXTURE * texture,int x,int y) {
pixels[pixelIndex + 3] = engine_generic_texture_color.a;
}
void engine_textureDestroy(struct ENGINE_TEXTURE * texture) {
void engine_texture_destroy(struct ENGINE_TEXTURE * texture) {
struct ENGINE_GENERIC_TEXTURE * fe_texture = (struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture);
engine_free(fe_texture->pixels);
engine_free(fe_texture);
engine_free(texture);
}
void engine_renderTexture2D(struct ENGINE_TEXTURE * texture,int sx,int sy) {
void engine_texture_render_2d(struct ENGINE_TEXTURE * texture,int sx,int sy) {
char * pixels = ((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels;
int ex = sx + texture->width;
if (ex > engine_width) { ex = engine_width; }
@ -62,8 +62,8 @@ void engine_renderTexture2D(struct ENGINE_TEXTURE * texture,int sx,int sy) {
while (y < ey) {
while (x < ex) {
pixelIndex = ((x - sx) + (y - sy) * texture->width)*4;
engine_setColor(pixels[pixelIndex],pixels[pixelIndex + 1],pixels[pixelIndex + 2],pixels[pixelIndex + 3]);
engine_drawPixel(x,y);
engine_surface_color_set(pixels[pixelIndex],pixels[pixelIndex + 1],pixels[pixelIndex + 2],pixels[pixelIndex + 3]);
engine_surface_draw_pixel(x,y);
++x;
}
x = sx;
@ -71,7 +71,7 @@ void engine_renderTexture2D(struct ENGINE_TEXTURE * texture,int sx,int sy) {
}
}
void engine_fileToTexture(struct ENGINE_TEXTURE * texture,char * fpath) {
void engine_texture_from_file(struct ENGINE_TEXTURE * texture,char * fpath) {
FILE * f = fopen(fpath,"r");
fgets(((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels,texture->width * texture->height,f);
fclose(f);

View File

@ -78,7 +78,7 @@ SDL_Window * engine_sdl_window;
int engine_width = 0;
int engine_height = 0;
struct ENGINE_EVENT engine_getEvent() {
struct ENGINE_EVENT engine_event_get() {
struct ENGINE_EVENT event;
SDL_Event sdlevent;
@ -113,7 +113,7 @@ struct ENGINE_EVENT engine_getEvent() {
return event;
}
void engine_sleep(long long ms) {
void engine_time_sleep(long long ms) {
SDL_Delay(ms);
}
@ -132,7 +132,7 @@ long long engine_time_get() {
#endif
Uint32 engine_sdl_color;
void engine_setColor(char r,char g,char b,char a) {
void engine_surface_color_set(char r,char g,char b,char a) {
#ifdef ENGINE_SDL_SKIP_COLOR
if (engine_sdl_skipc_interval == 0) {
if (engine_sdl_skipc_amount == 0) {
@ -186,7 +186,7 @@ void engine_setColor(char r,char g,char b,char a) {
char engine_sdl_skipp_amount = 0;
#endif
void engine_drawPixel(int x,int y) {
void engine_surface_draw_pixel(int x,int y) {
#ifdef ENGINE_SDL_SKIP_PIXEL
if (engine_sdl_skipp_interval == 0) {
if (engine_sdl_skipp_amount == 0) {
@ -246,7 +246,7 @@ void engine_drawPixel(int x,int y) {
#endif
}
void engine_render() {
void engine_window_present() {
#ifdef ENGINE_SDL_SKIP_FRAME
if (engine_sdl_skipf_interval == 0) {
if (engine_sdl_skipf_amount == 0) {
@ -270,7 +270,7 @@ void engine_render() {
#endif
}
void engine_init(int width,int height,char *title) {
void engine_window_init(int width,int height,char *title) {
SDL_Init(SDL_INIT_VIDEO);
engine_sdl_window = SDL_CreateWindow(title,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width * ENGINE_SDL_SCALE,height * ENGINE_SDL_SCALE,0);
#if (ENGINE_SDL_BUFFERTYPE == 0)
@ -286,7 +286,7 @@ void engine_init(int width,int height,char *title) {
engine_height = height;
#if (ENGINE_SDL_BUFFERTYPE == 1)
engine_setColor(0,0,0,255);
engine_surface_color_set(0,0,0,255);
#ifdef ENGINE_SDL_SKIP_COLOR
engine_sdl_skipc_interval = 0;
engine_sdl_skipc_amount = 0;

20
test.c
View File

@ -56,8 +56,8 @@ void tick() {
/*tr = (char)(((float)x / (float)engine_width) * 255);
tg = 255 - tr;
tb = (char)(((float)y / (float)engine_height) * 255);*/
engine_setColor(tr,tg,tb,255);
engine_drawPixel(x,y);
engine_surface_color_set(tr,tg,tb,255);
engine_surface_draw_pixel(x,y);
++x;
}
++y;
@ -101,15 +101,15 @@ void tick() {
/*tr = (char)(((float)x / (float)engine_width) * 255);
tg = 255 - tr;
tb = (char)(((float)y / (float)engine_height) * 255);*/
// engine_setColor(tr,tg,tb,128);
// engine_drawPixel(x,y);
// engine_surface_color_set(tr,tg,tb,128);
// engine_surface_draw_pixel(x,y);
// ++x;
// }
// ++y;
//}
engine_renderTexture2D(texture,5,5);
engine_texture_render_2d(texture,5,5);
frame += 1;
frameSec += 1;
@ -119,22 +119,22 @@ void tick() {
lastSec = tick;
frameSec = 0;
}
engine_render();
//engine_sleep(33);
engine_window_present();
//engine_time_sleep(33);
}
int main(int argc, char **argv) {
texture = engine_createTexture(8,8);
engine_fileToTexture(texture,"assets/textures/fier.rgba");
engine_texture_from_file(texture,"assets/textures/fier.rgba");
for (int i = 0; i < argc; ++i) {
printf("argv[%d]: %s\n", i, argv[i]);
}
engine_init(256,256,"Game");
engine_window_init(256,256,"Game");
while (1) {
struct ENGINE_EVENT event = engine_getEvent();
struct ENGINE_EVENT event = engine_event_get();
if (event.type != ENGINE_EVENT_TYPE_NONE) {
handleEvent(event);
} else {