Source

dark-hammer / src / engine / pybind / pyengine.i

The branch 'v0.4' does not exist.
/***********************************************************************************
 * Copyright (c) 2013, Sepehr Taghdisian
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 *
 ***********************************************************************************/

#if defined(SWIG)
%module pyeng

%{
#include "core/core.h"
#include "core/file-mgr.h"
#include "core/hash.h"
#include "core/vec-math.h"
#include "core/std-math.h"
#include "../engine.h"
#include "../camera.h"
#include "../scene-mgr.h"
#include "../gfx.h"
#include "../input.h"
#include "pyalloc.h"
%}

%include "typemaps.i"

%import "../../core/types.h"
#endif

/* core.h */
result_t core_init(bool_t trace_mem);
void core_release(bool_t report_leaks);

/* log.h */
enum log_type
{
    LOG_TEXT = 0,
    LOG_ERROR = 1,
    LOG_WARNING = 2,
    LOG_INFO = 3,
    LOG_LOAD = 4
};

result_t log_outputconsole(bool_t enable);
result_t log_outputfile(bool_t enable, const char* log_filepath);
result_t log_outputdebugger(bool_t enable);

/* error.h */
#define RET_OK 1
#define RET_FAIL 0

void err_print(const char* source, uint32 line, const char* text);
uint32 err_getcode();
void err_sendtolog(bool_t as_warning);
const char* err_getstring();
void err_clear();
bool_t err_haserrors();

/* std-math.h */
fl32 math_torad(fl32 deg);
fl32 math_todeg(fl32 rad);
bool_t math_isequal(fl32 a, fl32 b);

/* file-mgr.h */
void io_addvdir(const char* directory, bool_t monitor);
void io_clearvdirs();

/* hash.h */
uint32 hash_murmur32(const void* key, uint32 size_bytes, uint32 seed);

/* str.h */
void* str_toptr(const char* s);

/* vec-math.h */
struct vec4f 
{
    fl32 x;
    fl32 y;
    fl32 z;
    fl32 w;
};

struct vec4f* vec3_setf(struct vec4f* r, fl32 x, fl32 y, fl32 z);

/* init-params.h */
enum msaa_mode
{
    MSAA_NONE = 0, 
    MSAA_2X = 2,
    MSAA_4X = 4,
    MSAA_8X = 8
};

enum texture_quality
{
    TEXTURE_QUALITY_HIGH = 1,
    TEXTURE_QUALITY_NORMAL = 2,
    TEXTURE_QUALITY_LOW = 3,
    TEXTURE_QUALITY_HIGHEST = 0
};

enum texture_filter
{
    TEXTURE_FILTER_TRILINEAR = 0,
    TEXTURE_FILTER_BILINEAR,
    TEXTURE_FILTER_ANISO2X,
    TEXTURE_FILTER_ANISO4X,
    TEXTURE_FILTER_ANISO8X,
    TEXTURE_FILTER_ANISO16X
};

enum shading_quality
{
    SHADING_QUALITY_LOW = 2,
    SHADING_QUALITY_NORMAL = 1,
    SHADING_QUALITY_HIGH = 0
};

enum gfx_hwver
{
    GFX_HWVER_UNKNOWN = 0,
    GFX_HWVER_D3D11_0 = 3,
    GFX_HWVER_D3D10_1 = 2,
    GFX_HWVER_D3D10_0 = 1,
    GFX_HWVER_GL4_2 = 9,
    GFX_HWVER_GL4_0 = 8,
    GFX_HWVER_GL3_3 = 7,
    GFX_HWVER_GL3_2 = 6,
    GFX_HWVER_GL3_0 = 5
};

enum gfx_flags
{
    GFX_FLAG_FULLSCREEN = (1<<0),
    GFX_FLAG_VSYNC = (1<<1),
    GFX_FLAG_DEBUG = (1<<2),
    GFX_FLAG_FXAA = (1<<3),
    GFX_FLAG_REBUILDSHADERS = (1<<4)
};

enum eng_flags
{
    ENG_FLAG_DEBUG = (1<<0),
    ENG_FLAG_DEV = (1<<1),
    ENG_FLAG_EDITOR = (1<<2),
    ENG_FLAG_CONSOLE = (1<<3)
};

struct dev_params
{
    int32 fpsgraph_max;
    int32 ftgraph_max;
    int32 webserver_port;
};

struct gfx_params
{
    uint32 flags;
    enum msaa_mode msaa;
    enum texture_quality tex_quality;
    enum texture_filter tex_filter;
    enum shading_quality shading_quality;
    enum gfx_hwver hwver;
    uint32 adapter_id;
    uint32 width;
    uint32 height;
    uint32 refresh_rate;
#if defined(SWIGWIN)
    void* wnd;
#endif
};

struct init_params
{
    uint32 flags;
    uint32 lock_fps;
    uint32 console_lines_max;

    struct gfx_params gfx;
    struct dev_params dev;
    char* data_dir;
};

/* engine.h */
result_t eng_init(const struct init_params* params);
void eng_release();
void eng_update();

struct allocator* eng_get_framealloc();
struct allocator* eng_get_lsralloc();
struct allocator* eng_get_dataalloc();

/* camera.h */
struct camera
{
    struct vec4f look;
    struct vec4f pos;

    fl32 fnear;
    fl32 ffar;
    fl32 fov;
    fl32 aspect;
};

void cam_init(struct camera* cam, const struct vec4f* pos, const struct vec4f* lookat, 
    fl32 fnear, fl32 ffar, fl32 fov);
void cam_set_pitchconst(struct camera* cam, bool_t enable, 
    fl32 pitch_min, fl32 pitch_max);
void cam_set_viewsize(struct camera* cam, fl32 width, fl32 height);
void cam_update(struct camera* cam);
void cam_pitch(struct camera* cam, fl32 pitch);
void cam_yaw(struct camera* cam, fl32 yaw);
void cam_roll(struct camera* cam, fl32 roll);
void cam_fwd(struct camera* cam, fl32 dz);
void cam_strafe(struct camera* cam, fl32 dx);

/* scene-mgr.h */
uint32 scn_create_scene(const char* name);
void scn_destroy_scene(uint32 scene_id);
void scn_setactive(uint32 scene_id);
uint32 scn_getactive();
void scn_setcam(struct camera* cam);
struct camera* scn_getcam();

/* gfx.h */
typedef void (*pfn_debug_render)(gfx_cmdqueue cmdqueue, const struct gfx_view_params* params);
void gfx_resize(uint32 width, uint32 height);
void gfx_set_debug_renderfunc(pfn_debug_render fn);
%constant void gfx_render_grid(gfx_cmdqueue cmdqueue, const struct gfx_view_params* params);

/* input.h */
#if defined(SWIGWIN)
#define KEY_ESC 0x1B /*VK_ESCAPE*/
#define KEY_F1 0x70 /*VK_F1*/
#define KEY_F2 0x71 /*VK_F2*/
#define KEY_F3 0x72 /*VK_F3*/
#define KEY_F4 0x73 /*VK_F4*/
#define KEY_F5 0x74 /*VK_F5*/
#define KEY_F6 0x75 /*VK_F6*/
#define KEY_F7 0x76 /*VK_F7*/
#define KEY_F8 0x77 /*VK_F8*/
#define KEY_F9 0x78 /*VK_F9*/
#define KEY_F10 0x79 /*VK_F10*/
#define KEY_F11 0x7A /*VK_F11*/
#define KEY_F12 0x7B /*VK_F12*/
#define KEY_INSERT 0x2D /*VK_INSERT*/
#define KEY_PRINTSCREEN 0x2A /*VK_PRINT*/
#define KEY_BREAK 0x13 /*VK_PAUSE*/
#define KEY_TILDE 0xC0 /*VK_OEM_3*/
#define KEY_1 0x31
#define KEY_2 0x32
#define KEY_3 0x33
#define KEY_4 0x34
#define KEY_5 0x35
#define KEY_6 0x36
#define KEY_7 0x37
#define KEY_8 0x38
#define KEY_9 0x39
#define KEY_0 0x30
#define KEY_DASH 0xBD /*VK_OEM_MINUS*/
#define KEY_EQUAL 0xBB /*VK_OEM_PLUS*/
#define KEY_BACKSPACE 0x08 /*VK_BACK*/
#define KEY_TAB 0x09 /*VK_TAB*/
#define KEY_Q 0x51
#define KEY_W 0x57
#define KEY_E 0x45
#define KEY_R 0x52
#define KEY_T 0x54
#define KEY_Y 0x59
#define KEY_U 0x55
#define KEY_I 0x49
#define KEY_O 0x4F
#define KEY_P 0x50
#define KEY_BRACKET_OPEN 0xDB /*VK_OEM_4*/
#define KEY_BEACKET_CLOSE 0xDD /*VK_OEM_6*/
#define KEY_BACKSLASH 0xDC /*VK_OEM_5*/
#define KEY_CAPS 0x14 /*VK_CAPITAL*/
#define KEY_A 0x41
#define KEY_S 0x53
#define KEY_D 0x44
#define KEY_F 0x46
#define KEY_G 0x47
#define KEY_H 0x48
#define KEY_J 0x4A
#define KEY_K 0x4B
#define KEY_L 0x4C
#define KEY_SEMICOLON 0xBA /*VK_OEM_1*/
#define KEY_QUOTE 0xDE /*VK_OEM_7*/
#define KEY_ENTER 0x0D /*VK_RETURN*/
#define KEY_LSHIFT 0xA0 /*VK_LSHIFT*/
#define KEY_Z 0x5A
#define KEY_X 0x58
#define KEY_C 0x43
#define KEY_V 0x56
#define KEY_B 0x42
#define KEY_N 0x4E
#define KEY_M 0x4D
#define KEY_COMMA 0xBC /*VK_OEM_COMMA*/
#define KEY_DOT 0xBE /*VK_OEM_PERIOD*/
#define KEY_SLASH 0xBF /*VK_OEM_2*/
#define KEY_RSHIFT 0xA1 /*VK_RSHIFT*/
#define KEY_LCTRL 0xA2 /*VK_LCONTROL*/
#define KEY_LALT 0xA4 /*VK_LMENU*/
#define KEY_SPACE 0x20 /*VK_SPACE*/
#define KEY_RALT 0xA5 /*VK_RMENU*/
#define KEY_RCTRL 0xA3 /*VK_RCONTROL*/
#define KEY_DELETE 0x2E /*VK_DELETE*/
#define KEY_INSERT 0x2D /*VK_INSERT*/
#define KEY_HOME 0x24 /*VK_HOME*/
#define KEY_END 0x23 /*VK_END*/
#define KEY_PGUP 0x21 /*VK_PRIOR*/
#define KEY_PGDWN 0x22 /*VK_NEXT*/
#define KEY_UP 0x26 /*VK_UP*/
#define KEY_DOWN 0x28 /*VK_DOWN*/
#define KEY_LEFT 0x25 /*VK_LEFT*/
#define KEY_RIGHT 0x27 /*VK_RIGHT*/
#define KEY_NUM_DIVIDE 0x6F /*VK_DIVIDE*/
#define KEY_NUM_MULTIPLY 0x6A /*VK_MULTIPLY*/
#define KEY_NUM_MINUS 0x6D /*VK_SUBTRACT*/
#define KEY_NUM_PLUS 0x6B /*VK_ADD*/
#define KEY_NUM_ENTER 0x6C /*VK_SEPARATOR*/
#define KEY_NUM_DOT 0x6E /*VK_DECIMAL*/
#define KEY_NUM_1 0x61 /*VK_NUMPAD1*/
#define KEY_NUM_2 0x62 /*VK_NUMPAD2*/
#define KEY_NUM_3 0x63 /*VK_NUMPAD3*/
#define KEY_NUM_4 0x64 /*VK_NUMPAD4*/
#define KEY_NUM_5 0x65 /*VK_NUMPAD5*/
#define KEY_NUM_6 0x66 /*VK_NUMPAD6*/
#define KEY_NUM_7 0x67 /*VK_NUMPAD7*/
#define KEY_NUM_8 0x68 /*VK_NUMPAD8*/
#define KEY_NUM_9 0x69 /*VK_NUMPAD9*/
#define KEY_NUM_0 0x60 /*VK_NUMPAD0*/
#define KEY_NUM_LOCK 0x90 /*VK_NUMLOCK*/
#endif

enum input_mouse_key
{
	INPUT_MOUSEKEY_NONE = 0,
	INPUT_MOUSEKEY_LEFT = (1 << 0),
	INPUT_MOUSEKEY_RIGHT = (1 << 1),
	INPUT_MOUSEKEY_MIDDLE = (1 << 2),
	INPUT_MOUSEKEY_WHEELUP = (1 << 3),
	INPUT_MOUSEKEY_WHEELDWN = (1 << 4)
};

bool_t input_get_kbhit(uint32 keycode);
bool_t input_get_mouse(int *OUTPUT, int *OUTPUT, unsigned int *OUTPUT);
void input_update(void* display, void* wnd);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.