forked from Fierelier/me.fier.engine
Update function names
This commit is contained in:
parent
b1e828c0ca
commit
0201ffb6e6
24
README.txt
24
README.txt
@ -2,25 +2,27 @@ A software accelerated (CPU-only) game engine for older computers. It uses a lay
|
|||||||
|
|
||||||
>>> FUNCTIONS
|
>>> FUNCTIONS
|
||||||
>> WINDOW
|
>> WINDOW
|
||||||
> void engine_init(int width,int height,char * title)
|
> void engine_window_init(int width,int height,char * title)
|
||||||
> void engine_setColor(char r,char g,char b,char a)
|
> void engine_window_present()
|
||||||
> void engine_drawPixel(int x,int y)
|
|
||||||
> void engine_render()
|
>> SURFACE
|
||||||
|
> void engine_surface_color_set(char r,char g,char b,char a)
|
||||||
|
> void engine_surface_draw_pixel(int x,int y)
|
||||||
|
|
||||||
>> TIME
|
>> TIME
|
||||||
> long long engine_time_get()
|
> long long engine_time_get()
|
||||||
> void engine_sleep(long long ms)
|
> void engine_time_sleep(long long ms)
|
||||||
|
|
||||||
>> LOGIC
|
>> LOGIC
|
||||||
> struct ENGINE_EVENT engine_get_event()
|
> struct ENGINE_EVENT engine_event_get()
|
||||||
|
|
||||||
>> TEXTURES
|
>> TEXTURES
|
||||||
struct ENGINE_TEXTURE engine_createTexture(int width,int height)
|
struct ENGINE_TEXTURE engine_createTexture(int width,int height)
|
||||||
> void engine_textureSetColor(char r,char g,char b,char a)
|
> void engine_texture_color_set(char r,char g,char b,char 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)
|
||||||
> void engine_textureDestroy(struct ENGINE_TEXTURE * texture)
|
> void engine_texture_destroy(struct ENGINE_TEXTURE * 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)
|
||||||
> void engine_fileToTexture(struct ENGINE_TEXTURE * texture,char * fpath)
|
> void engine_texture_from_file(struct ENGINE_TEXTURE * texture,char * fpath)
|
||||||
|
|
||||||
>>> EVENTS
|
>>> 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:
|
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
8
main.c
@ -26,8 +26,8 @@ void tick() {
|
|||||||
}
|
}
|
||||||
luaL_loadstring(engine_lua_state,"engine_onFrame()");
|
luaL_loadstring(engine_lua_state,"engine_onFrame()");
|
||||||
lua_call(engine_lua_state,0,0);
|
lua_call(engine_lua_state,0,0);
|
||||||
engine_render();
|
engine_window_present();
|
||||||
//engine_sleep(33);
|
//engine_time_sleep(33);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -35,11 +35,11 @@ int main(int argc, char **argv) {
|
|||||||
printf("argv[%d]: %s\n", i, argv[i]);
|
printf("argv[%d]: %s\n", i, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine_init(96,64,"Game");
|
engine_window_init(96,64,"Game");
|
||||||
engine_luaInit();
|
engine_luaInit();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct ENGINE_EVENT event = engine_getEvent();
|
struct ENGINE_EVENT event = engine_event_get();
|
||||||
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
||||||
handleEvent(event);
|
handleEvent(event);
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ lua_State * engine_lua_state;
|
|||||||
|
|
||||||
int engine_luafSleep(lua_State *L) {
|
int engine_luafSleep(lua_State *L) {
|
||||||
int time = luaL_checkinteger(L,1);
|
int time = luaL_checkinteger(L,1);
|
||||||
engine_sleep(time);
|
engine_time_sleep(time);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ int engine_luafLoadTexture(lua_State *L) {
|
|||||||
int width = luaL_checkinteger(L,2);
|
int width = luaL_checkinteger(L,2);
|
||||||
int height = luaL_checkinteger(L,3);
|
int height = luaL_checkinteger(L,3);
|
||||||
struct ENGINE_TEXTURE * texture = engine_createTexture(width,height);
|
struct ENGINE_TEXTURE * texture = engine_createTexture(width,height);
|
||||||
engine_fileToTexture(texture,fpath);
|
engine_texture_from_file(texture,fpath);
|
||||||
lua_pushlightuserdata(L,texture);
|
lua_pushlightuserdata(L,texture);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ int engine_luafRenderTexture2D(lua_State *L) {
|
|||||||
struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1);
|
struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1);
|
||||||
int x = luaL_checkinteger(L,2);
|
int x = luaL_checkinteger(L,2);
|
||||||
int y = luaL_checkinteger(L,3);
|
int y = luaL_checkinteger(L,3);
|
||||||
engine_renderTexture2D(texture,x,y);
|
engine_texture_render_2d(texture,x,y);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 { char r; char g; char b; char a; };
|
||||||
struct ENGINE_GENERIC_TEXTURE_COLOR engine_generic_texture_color;
|
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.r = r;
|
||||||
engine_generic_texture_color.g = g;
|
engine_generic_texture_color.g = g;
|
||||||
engine_generic_texture_color.b = b;
|
engine_generic_texture_color.b = b;
|
||||||
engine_generic_texture_color.a = a;
|
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;
|
char * pixels = ((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels;
|
||||||
long pixelIndex = (x + y * texture->width) * 4;
|
long pixelIndex = (x + y * texture->width) * 4;
|
||||||
pixels[pixelIndex + 0] = engine_generic_texture_color.r;
|
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;
|
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);
|
struct ENGINE_GENERIC_TEXTURE * fe_texture = (struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture);
|
||||||
engine_free(fe_texture->pixels);
|
engine_free(fe_texture->pixels);
|
||||||
engine_free(fe_texture);
|
engine_free(fe_texture);
|
||||||
engine_free(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;
|
char * pixels = ((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels;
|
||||||
int ex = sx + texture->width;
|
int ex = sx + texture->width;
|
||||||
if (ex > engine_width) { ex = engine_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 (y < ey) {
|
||||||
while (x < ex) {
|
while (x < ex) {
|
||||||
pixelIndex = ((x - sx) + (y - sy) * texture->width)*4;
|
pixelIndex = ((x - sx) + (y - sy) * texture->width)*4;
|
||||||
engine_setColor(pixels[pixelIndex],pixels[pixelIndex + 1],pixels[pixelIndex + 2],pixels[pixelIndex + 3]);
|
engine_surface_color_set(pixels[pixelIndex],pixels[pixelIndex + 1],pixels[pixelIndex + 2],pixels[pixelIndex + 3]);
|
||||||
engine_drawPixel(x,y);
|
engine_surface_draw_pixel(x,y);
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
x = sx;
|
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");
|
FILE * f = fopen(fpath,"r");
|
||||||
fgets(((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels,texture->width * texture->height,f);
|
fgets(((struct ENGINE_GENERIC_TEXTURE *)(texture->fe_texture))->pixels,texture->width * texture->height,f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -78,7 +78,7 @@ SDL_Window * engine_sdl_window;
|
|||||||
int engine_width = 0;
|
int engine_width = 0;
|
||||||
int engine_height = 0;
|
int engine_height = 0;
|
||||||
|
|
||||||
struct ENGINE_EVENT engine_getEvent() {
|
struct ENGINE_EVENT engine_event_get() {
|
||||||
struct ENGINE_EVENT event;
|
struct ENGINE_EVENT event;
|
||||||
SDL_Event sdlevent;
|
SDL_Event sdlevent;
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ struct ENGINE_EVENT engine_getEvent() {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void engine_sleep(long long ms) {
|
void engine_time_sleep(long long ms) {
|
||||||
SDL_Delay(ms);
|
SDL_Delay(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ long long engine_time_get() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Uint32 engine_sdl_color;
|
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
|
#ifdef ENGINE_SDL_SKIP_COLOR
|
||||||
if (engine_sdl_skipc_interval == 0) {
|
if (engine_sdl_skipc_interval == 0) {
|
||||||
if (engine_sdl_skipc_amount == 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;
|
char engine_sdl_skipp_amount = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void engine_drawPixel(int x,int y) {
|
void engine_surface_draw_pixel(int x,int y) {
|
||||||
#ifdef ENGINE_SDL_SKIP_PIXEL
|
#ifdef ENGINE_SDL_SKIP_PIXEL
|
||||||
if (engine_sdl_skipp_interval == 0) {
|
if (engine_sdl_skipp_interval == 0) {
|
||||||
if (engine_sdl_skipp_amount == 0) {
|
if (engine_sdl_skipp_amount == 0) {
|
||||||
@ -246,7 +246,7 @@ void engine_drawPixel(int x,int y) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void engine_render() {
|
void engine_window_present() {
|
||||||
#ifdef ENGINE_SDL_SKIP_FRAME
|
#ifdef ENGINE_SDL_SKIP_FRAME
|
||||||
if (engine_sdl_skipf_interval == 0) {
|
if (engine_sdl_skipf_interval == 0) {
|
||||||
if (engine_sdl_skipf_amount == 0) {
|
if (engine_sdl_skipf_amount == 0) {
|
||||||
@ -270,7 +270,7 @@ void engine_render() {
|
|||||||
#endif
|
#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);
|
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);
|
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)
|
#if (ENGINE_SDL_BUFFERTYPE == 0)
|
||||||
@ -286,7 +286,7 @@ void engine_init(int width,int height,char *title) {
|
|||||||
engine_height = height;
|
engine_height = height;
|
||||||
|
|
||||||
#if (ENGINE_SDL_BUFFERTYPE == 1)
|
#if (ENGINE_SDL_BUFFERTYPE == 1)
|
||||||
engine_setColor(0,0,0,255);
|
engine_surface_color_set(0,0,0,255);
|
||||||
#ifdef ENGINE_SDL_SKIP_COLOR
|
#ifdef ENGINE_SDL_SKIP_COLOR
|
||||||
engine_sdl_skipc_interval = 0;
|
engine_sdl_skipc_interval = 0;
|
||||||
engine_sdl_skipc_amount = 0;
|
engine_sdl_skipc_amount = 0;
|
||||||
|
20
test.c
20
test.c
@ -56,8 +56,8 @@ void tick() {
|
|||||||
/*tr = (char)(((float)x / (float)engine_width) * 255);
|
/*tr = (char)(((float)x / (float)engine_width) * 255);
|
||||||
tg = 255 - tr;
|
tg = 255 - tr;
|
||||||
tb = (char)(((float)y / (float)engine_height) * 255);*/
|
tb = (char)(((float)y / (float)engine_height) * 255);*/
|
||||||
engine_setColor(tr,tg,tb,255);
|
engine_surface_color_set(tr,tg,tb,255);
|
||||||
engine_drawPixel(x,y);
|
engine_surface_draw_pixel(x,y);
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
++y;
|
++y;
|
||||||
@ -101,15 +101,15 @@ void tick() {
|
|||||||
/*tr = (char)(((float)x / (float)engine_width) * 255);
|
/*tr = (char)(((float)x / (float)engine_width) * 255);
|
||||||
tg = 255 - tr;
|
tg = 255 - tr;
|
||||||
tb = (char)(((float)y / (float)engine_height) * 255);*/
|
tb = (char)(((float)y / (float)engine_height) * 255);*/
|
||||||
// engine_setColor(tr,tg,tb,128);
|
// engine_surface_color_set(tr,tg,tb,128);
|
||||||
// engine_drawPixel(x,y);
|
// engine_surface_draw_pixel(x,y);
|
||||||
// ++x;
|
// ++x;
|
||||||
// }
|
// }
|
||||||
// ++y;
|
// ++y;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
engine_renderTexture2D(texture,5,5);
|
engine_texture_render_2d(texture,5,5);
|
||||||
|
|
||||||
frame += 1;
|
frame += 1;
|
||||||
frameSec += 1;
|
frameSec += 1;
|
||||||
@ -119,22 +119,22 @@ void tick() {
|
|||||||
lastSec = tick;
|
lastSec = tick;
|
||||||
frameSec = 0;
|
frameSec = 0;
|
||||||
}
|
}
|
||||||
engine_render();
|
engine_window_present();
|
||||||
//engine_sleep(33);
|
//engine_time_sleep(33);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
texture = engine_createTexture(8,8);
|
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) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
printf("argv[%d]: %s\n", i, argv[i]);
|
printf("argv[%d]: %s\n", i, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine_init(256,256,"Game");
|
engine_window_init(256,256,"Game");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct ENGINE_EVENT event = engine_getEvent();
|
struct ENGINE_EVENT event = engine_event_get();
|
||||||
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
||||||
handleEvent(event);
|
handleEvent(event);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user