split some files

This commit is contained in:
NishiOwO 2025-03-29 15:08:45 +09:00
parent 67d50d1f22
commit e77b60a22a
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
13 changed files with 145 additions and 41 deletions

54
engine/GLX_draw.c Normal file
View File

@ -0,0 +1,54 @@
#define NB_EXPOSE_DRAW_PLATFORM
/* External library */
/* Interface */
#include "nb_draw_platform.h"
/* NishBox */
#include "nb_log.h"
/* Standard */
void _nb_draw_create(nb_draw_t** pdraw) {
nb_draw_t* draw = *pdraw;
int i;
int attribs[64];
int screen;
Window root;
XVisualInfo* visual;
draw->display = XOpenDisplay(NULL);
if(draw->display == NULL) {
nb_function_log("Failed to open display", "");
_nb_draw_destroy(draw);
*pdraw = NULL;
return;
}
attribs[i++] = GLX_RGBA;
attribs[i++] = GLX_DOUBLEBUFFER;
attribs[i++] = GLX_RED_SIZE;
attribs[i++] = 1;
attribs[i++] = GLX_GREEN_SIZE;
attribs[i++] = 1;
attribs[i++] = GLX_BLUE_SIZE;
attribs[i++] = 1;
attribs[i++] = GLX_DEPTH_SIZE;
attribs[i++] = 1;
attribs[i++] = None;
screen = DefaultScreen(draw->display);
root = RootWindow(draw->display, screen);
visual = glXChooseVisual(draw->display, screen, attribs);
if(visual == NULL) {
nb_function_log("Failed to get a visual", "");
_nb_draw_destroy(draw);
}
XFree(visual);
}
void _nb_draw_destroy(nb_draw_t* draw) {
if(draw->display != NULL) XCloseDisplay(draw->display);
}

View File

@ -1,5 +1,5 @@
TARGET = libnishbox.a
OBJS = version.o core.o draw.o log.o
OBJS = version.o core.o draw.o log.o $(BACKEND)_draw.o
include ../common.mk

15
engine/WGL_draw.c Normal file
View File

@ -0,0 +1,15 @@
#define NB_EXPOSE_DRAW_PLATFORM
/* External library */
/* Interface */
#include "nb_draw_platform.h"
/* NishBox */
#include "nb_log.h"
/* Standard */
void _nb_draw_create(nb_draw_t** pdraw) { nb_draw_t* draw = *pdraw; }
void _nb_draw_destroy(nb_draw_t* draw) {}

View File

@ -1,18 +1,25 @@
#define NB_EXPOSE_CORE
/* External library */
#include <ode/ode.h>
/* Interface */
#include "nb_core.h"
/* NishBox */
#include "nb_draw.h"
#include "nb_log.h"
#include "nb_version.h"
/* Standard */
#include <stdlib.h>
void nb_engine_begin(void) { dInitODE(); }
void nb_engine_begin(void) {
nb_version_t ver;
nb_get_version(&ver);
nb_function_log("NishBox engine %s", ver.full);
nb_function_log("OpenGL backend: %s", ver.opengl);
dInitODE();
}
void nb_engine_end(void) { dCloseODE(); }
@ -20,6 +27,7 @@ nb_engine_t* nb_engine_create(void) {
nb_engine_t* engine = malloc(sizeof(*engine));
engine->draw = nb_draw_create();
if(engine->draw == NULL) {
nb_function_log("Failed to create drawing interface", "");
free(engine);
return NULL;
}

View File

@ -1,33 +1,28 @@
#define NB_EXPOSE_DRAW
#define NB_EXPOSE_DRAW_PLATFORM
/* External library */
#include <GL/gl.h>
#if defined(USE_GLX)
#include <X11/Xlib.h>
#include <GL/glx.h>
#elif defined(USE_WGL)
#include <windows.h>
#endif
/* Interface */
#include "nb_draw.h"
/* NishBox */
#include "nb_log.h"
#include "nb_draw_platform.h"
/* Standard */
#include <stdlib.h>
#include <string.h>
nb_draw_t* nb_draw_create(void) {
nb_draw_t* draw = malloc(sizeof(*draw));
#if defined(USE_GLX)
draw->display = XOpenDisplay(NULL);
if(draw->display == NULL) {
free(draw);
return NULL;
memset(draw, 0, sizeof(*draw));
_nb_draw_create(&draw);
if(draw != NULL) {
nb_function_log("Created drawing interface successfully", "");
}
NB_LOG("test");
#elif defined(USE_WGL)
#endif
return draw;
}
void nb_draw_destroy(nb_draw_t* draw) { _nb_draw_destroy(draw); }

View File

@ -4,6 +4,9 @@
#include <nb_macro.h>
/* External library */
#ifdef NB_EXPOSE_CORE
#include <ode/ode.h>
#endif
/* NishBox */
#ifdef NB_EXPOSE_CORE

View File

@ -6,26 +6,11 @@
/* External library */
/* NishBox */
#include <nb_draw_platform.h>
/* Standard */
#ifdef NB_EXPOSE_DRAW
typedef struct nb_draw {
#if defined(USE_GLX)
Display* display;
Window window;
GLXContext context;
#elif defined(USE_WGL)
HINSTANCE instance;
HWND window;
HDC dc;
HGLRC glrc;
#endif
} nb_draw_t;
#else
typedef void nb_draw_t;
#endif
nb_draw_t* nb_draw_create(void);
void nb_draw_destroy(nb_draw_t* draw);
#endif

40
engine/nb_draw_platform.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef __NB_DRAW_PLATFORM_H__
#define __NB_DRAW_PLATFORM_H__
#include <nb_macro.h>
/* External library */
#ifdef NB_EXPOSE_DRAW_PLATFORM
#if defined(USE_GLX)
#include <X11/Xlib.h>
#include <GL/glx.h>
#elif defined(USE_WGL)
#include <windows.h>
#endif
#endif
/* NishBox */
/* Standard */
#ifdef NB_EXPOSE_DRAW_PLATFORM
typedef struct nb_draw {
#if defined(USE_GLX)
Display* display;
Window window;
GLXContext context;
#elif defined(USE_WGL)
HINSTANCE instance;
HWND window;
HDC dc;
HGLRC glrc;
#endif
} nb_draw_t;
#else
typedef void nb_draw_t;
#endif
void _nb_draw_create(nb_draw_t** pdraw);
void _nb_draw_destroy(nb_draw_t* draw);
#endif

View File

@ -11,7 +11,6 @@
void nb_log(const char* fmt, ...);
#define NB_FORMAT_LOG(fmt, arg...) nb_log("%s: " fmt "\n", __FUNCTION_NAME__, arg)
#define NB_LOG(fmt) nb_log("%s: " fmt "\n", __FUNCTION_NAME__)
#define nb_function_log(fmt, arg...) nb_log("%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, arg)
#endif

View File

@ -11,6 +11,10 @@
#define NB_EXPOSE_DRAW
#endif
#ifndef NB_EXPOSE_DRAW_PLATFORM
#define NB_EXPOSE_DRAW_PLATFORM
#endif
#endif
#ifndef __FUNCTION_NAME__

View File

@ -14,6 +14,7 @@ typedef struct nb_version {
int minor;
int patch;
char full[64];
char opengl[32];
} nb_version_t;
void nb_get_version(nb_version_t* version);

View File

@ -18,6 +18,11 @@ void nb_get_version(nb_version_t* version) {
int old = 0;
strcpy(cpstr, NB_VERSION);
strcpy(version->full, NB_VERSION);
#if defined(USE_GLX)
strcpy(version->opengl, "GLX");
#elif defined(USE_WGL)
strcpy(version->opengl, "WGL");
#endif
for(i = 0;; i++) {
if(cpstr[i] == '.' || cpstr[i] == 0) {
int num;

View File

@ -1,5 +1,4 @@
/* NishBox */
#include <nb_version.h>
#include <nb_core.h>
/* External library */
@ -10,10 +9,6 @@
nb_engine_t* engine;
int main(int argc, char** argv) {
nb_version_t ver;
nb_get_version(&ver);
printf("NishBox engine %s - Powered by Pawn and ODE\n", ver.full);
nb_engine_begin();
engine = nb_engine_create();
if(engine == NULL) {