script api revamp
parent
0c07910f0f
commit
0f817be23a
1793
bind/v4k.lua
1793
bind/v4k.lua
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,81 @@
|
|||
#include "v4k.h"
|
||||
|
||||
vec3 campos1;
|
||||
vec3 campos2;
|
||||
tween_t anim;
|
||||
bool cam_tween_reset=1;
|
||||
camera_t cam;
|
||||
#define NUM_SAMPLES 64
|
||||
|
||||
int tick_mode = 0;
|
||||
|
||||
static double smooth_delta() {
|
||||
static double time_samples[NUM_SAMPLES] = {0};
|
||||
static int curr_index = 0;
|
||||
double time = window_delta();
|
||||
|
||||
time_samples[curr_index] = time;
|
||||
if (++curr_index == NUM_SAMPLES)
|
||||
curr_index = 0;
|
||||
|
||||
double average = 0;
|
||||
for (int i = NUM_SAMPLES; i--; )
|
||||
average += time_samples[i];
|
||||
average /= NUM_SAMPLES;
|
||||
|
||||
time = min(time, average);
|
||||
return time;
|
||||
}
|
||||
|
||||
bool intro_camera() {
|
||||
const float START_MOVING_ONTO_PLANET = 1.5f;
|
||||
const float STAY_PUT_AT_PLANET = 4.0f;
|
||||
const float ZOOM_OUT_TO_BOARD = 5.0f;
|
||||
const float STAY_STILL = 6.0f;
|
||||
const float LIFT_OFF = 7.0f;
|
||||
if (cam_tween_reset) {
|
||||
anim = tween();
|
||||
tween_setkey(&anim, 0.0f, campos1, EASE_QUAD);
|
||||
tween_setkey(&anim, START_MOVING_ONTO_PLANET, campos1, EASE_QUAD);
|
||||
tween_setkey(&anim, STAY_PUT_AT_PLANET, campos2, EASE_QUAD);
|
||||
tween_setkey(&anim, ZOOM_OUT_TO_BOARD, campos2, EASE_QUAD);
|
||||
tween_setkey(&anim, LIFT_OFF, campos1, EASE_QUAD);
|
||||
cam_tween_reset=0;
|
||||
}
|
||||
|
||||
float val = !tick_mode ? window_delta() : tick_mode == 1 ? smooth_delta() : 0.016f;
|
||||
printf("dt: %.04f\n", val);
|
||||
bool done = tween_update(&anim, val) == 1.0f;
|
||||
cam.position = anim.result;
|
||||
camera_lookat(&cam, vec3(cam.position.x,0,cam.position.z));
|
||||
return done;
|
||||
}
|
||||
|
||||
void reset_intro() {
|
||||
cam_tween_reset=1;
|
||||
tween_destroy(&anim);
|
||||
|
||||
campos1 = vec3(0.0f, 5.0f, 0.0f);
|
||||
campos2 = vec3(0.0f, 25.0f, 0.0f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
window_create(75.0, WINDOW_FULLSCREEN|WINDOW_SQUARE/*|WINDOW_VSYNC_DISABLED*/);
|
||||
// window_fps_unlock();
|
||||
// window_fps_lock(60.0);
|
||||
|
||||
cam = camera();
|
||||
reset_intro();
|
||||
|
||||
while( window_swap() && !input(KEY_ESC) ) { // game loop
|
||||
if (intro_camera())
|
||||
reset_intro();
|
||||
|
||||
ddraw_circle(vec3(0,0,0), vec3(0,-1,0), 1.5f);
|
||||
|
||||
if (input_down(KEY_SPACE))
|
||||
tick_mode = ++tick_mode % 3;
|
||||
|
||||
ddraw_text2d(vec2(15, 95), va("mode: %s\n", !tick_mode ? "delta time" : tick_mode == 1 ? "avg delta time" : "fixed time increment"));
|
||||
}
|
||||
}
|
|
@ -14232,7 +14232,10 @@ extern "C" {
|
|||
#define ASSERT(expr, ...) do { int fool_msvc[] = {0,}; if(!(expr)) { fool_msvc[0]++; alert(va("!Expression failed: " #expr " " FILELINE "\n" __VA_ARGS__)), breakpoint(); } } while(0)
|
||||
#define ASSERT_ONCE(expr, ...) do { int fool_msvc[] = {0,}; if(!(expr)) { fool_msvc[0]++; static int seen = 0; if(!seen) seen = 1, alert(va("!Expression failed: " #expr " " FILELINE "\n" __VA_ARGS__)), breakpoint(); } } while(0)
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_ASSERT
|
||||
#define STATIC_ASSERT(EXPR) typedef struct { unsigned macro(static_assert_on_L) : !!(EXPR); } unique(static_assert_on_L)
|
||||
#endif
|
||||
|
||||
#define FILELINE __FILE__ ":" STRINGIZE(__LINE__)
|
||||
#define STRINGIZE(x) STRINGIZ3(x)
|
||||
|
@ -15219,8 +15222,10 @@ API bool id_valid(uintptr_t id);
|
|||
array(struct obj*) objchildren; \
|
||||
};
|
||||
|
||||
#ifndef OBJ
|
||||
#define OBJ \
|
||||
OBJHEADER
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// syntax sugars
|
||||
|
@ -15257,8 +15262,10 @@ API bool id_valid(uintptr_t id);
|
|||
#define OBJCOMPONENTS_ALL_FLAGGED 0x5555555555555555ULL
|
||||
#define COMPONENTS_ONLY(x) ((x) & ~OBJCOMPONENTS_ALL_FLAGGED)
|
||||
|
||||
#ifndef ENTITY
|
||||
#define ENTITY \
|
||||
struct { OBJHEADER union { struct { uintptr_t objenabled:OBJCOMPONENTS_MAX, objflagged:OBJCOMPONENTS_MAX; }; uintptr_t cflags; }; void *c[OBJCOMPONENTS_MAX]; };
|
||||
#endif
|
||||
|
||||
#define TYPEDEF_ENTITY(NAME,N,...) \
|
||||
typedef struct NAME { ENTITY \
|
||||
|
@ -15925,7 +15932,15 @@ API void* dll(const char *filename, const char *symbol);
|
|||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
API void script_init();
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void script_init(); // @deprecate
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_push(void *env);
|
||||
|
||||
API void script_run(const char *script);
|
||||
API void script_runfile(const char *pathfile);
|
||||
|
||||
|
@ -15935,15 +15950,7 @@ API void script_call(const char *lua_function);
|
|||
|
||||
API bool script_tests();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_pop();
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_file.h"
|
||||
|
@ -360119,7 +360126,10 @@ int main() { int (*adder)() = dll("demo.dll", "add2"); printf("%d\n", adder(2,3)
|
|||
|
||||
typedef lua_State lua;
|
||||
|
||||
// the Lua interpreter
|
||||
// the Lua interpreter(s)
|
||||
static array(lua*) Ls;
|
||||
|
||||
// the **current** Lua interpreter
|
||||
static lua *L;
|
||||
|
||||
#if is(linux)
|
||||
|
@ -360364,6 +360374,16 @@ void *script_init_env(unsigned flags) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool script_push(void *env) {
|
||||
array_push(Ls, L = env);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool script_pop() {
|
||||
L = array_count(Ls) && (array_pop(Ls), array_count(Ls)) ? *array_back(Ls) : NULL;
|
||||
return !!array_count(Ls);
|
||||
}
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_file.c"
|
||||
|
@ -376887,7 +376907,8 @@ bool steam_init(unsigned app_id) {
|
|||
return !strcpy(steam.status, "Err: steam not running");
|
||||
}
|
||||
|
||||
SteamAPI_RestartAppIfNecessary(app_id);
|
||||
if( SteamAPI_RestartAppIfNecessary(app_id) )
|
||||
exit(0); // restarting app thru Steam client if needed
|
||||
|
||||
// Create interfaces
|
||||
steam.iclient = (intptr_t)SteamInternal_CreateInterface("SteamClient020");
|
||||
|
|
|
@ -201,7 +201,10 @@
|
|||
#define ASSERT(expr, ...) do { int fool_msvc[] = {0,}; if(!(expr)) { fool_msvc[0]++; alert(va("!Expression failed: " #expr " " FILELINE "\n" __VA_ARGS__)), breakpoint(); } } while(0)
|
||||
#define ASSERT_ONCE(expr, ...) do { int fool_msvc[] = {0,}; if(!(expr)) { fool_msvc[0]++; static int seen = 0; if(!seen) seen = 1, alert(va("!Expression failed: " #expr " " FILELINE "\n" __VA_ARGS__)), breakpoint(); } } while(0)
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_ASSERT
|
||||
#define STATIC_ASSERT(EXPR) typedef struct { unsigned macro(static_assert_on_L) : !!(EXPR); } unique(static_assert_on_L)
|
||||
#endif
|
||||
|
||||
#define FILELINE __FILE__ ":" STRINGIZE(__LINE__)
|
||||
#define STRINGIZE(x) STRINGIZ3(x)
|
||||
|
|
|
@ -41,7 +41,10 @@ int main() { int (*adder)() = dll("demo.dll", "add2"); printf("%d\n", adder(2,3)
|
|||
|
||||
typedef lua_State lua;
|
||||
|
||||
// the Lua interpreter
|
||||
// the Lua interpreter(s)
|
||||
static array(lua*) Ls;
|
||||
|
||||
// the **current** Lua interpreter
|
||||
static lua *L;
|
||||
|
||||
#if is(linux)
|
||||
|
@ -286,3 +289,13 @@ void *script_init_env(unsigned flags) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool script_push(void *env) {
|
||||
array_push(Ls, L = env);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool script_pop() {
|
||||
L = array_count(Ls) && (array_pop(Ls), array_count(Ls)) ? *array_back(Ls) : NULL;
|
||||
return !!array_count(Ls);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,15 @@ API void* dll(const char *filename, const char *symbol);
|
|||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
API void script_init();
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void script_init(); // @deprecate
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_push(void *env);
|
||||
|
||||
API void script_run(const char *script);
|
||||
API void script_runfile(const char *pathfile);
|
||||
|
||||
|
@ -23,12 +31,4 @@ API void script_call(const char *lua_function);
|
|||
|
||||
API bool script_tests();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_pop();
|
||||
|
|
|
@ -55,8 +55,10 @@ API bool id_valid(uintptr_t id);
|
|||
array(struct obj*) objchildren; \
|
||||
};
|
||||
|
||||
#ifndef OBJ
|
||||
#define OBJ \
|
||||
OBJHEADER
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// syntax sugars
|
||||
|
@ -93,8 +95,10 @@ API bool id_valid(uintptr_t id);
|
|||
#define OBJCOMPONENTS_ALL_FLAGGED 0x5555555555555555ULL
|
||||
#define COMPONENTS_ONLY(x) ((x) & ~OBJCOMPONENTS_ALL_FLAGGED)
|
||||
|
||||
#ifndef ENTITY
|
||||
#define ENTITY \
|
||||
struct { OBJHEADER union { struct { uintptr_t objenabled:OBJCOMPONENTS_MAX, objflagged:OBJCOMPONENTS_MAX; }; uintptr_t cflags; }; void *c[OBJCOMPONENTS_MAX]; };
|
||||
#endif
|
||||
|
||||
#define TYPEDEF_ENTITY(NAME,N,...) \
|
||||
typedef struct NAME { ENTITY \
|
||||
|
|
|
@ -88,7 +88,8 @@ bool steam_init(unsigned app_id) {
|
|||
return !strcpy(steam.status, "Err: steam not running");
|
||||
}
|
||||
|
||||
SteamAPI_RestartAppIfNecessary(app_id);
|
||||
if( SteamAPI_RestartAppIfNecessary(app_id) )
|
||||
exit(0); // restarting app thru Steam client if needed
|
||||
|
||||
// Create interfaces
|
||||
steam.iclient = (intptr_t)SteamInternal_CreateInterface("SteamClient020");
|
||||
|
|
15
engine/v4k.c
15
engine/v4k.c
|
@ -7273,7 +7273,10 @@ int main() { int (*adder)() = dll("demo.dll", "add2"); printf("%d\n", adder(2,3)
|
|||
|
||||
typedef lua_State lua;
|
||||
|
||||
// the Lua interpreter
|
||||
// the Lua interpreter(s)
|
||||
static array(lua*) Ls;
|
||||
|
||||
// the **current** Lua interpreter
|
||||
static lua *L;
|
||||
|
||||
#if is(linux)
|
||||
|
@ -7518,6 +7521,16 @@ void *script_init_env(unsigned flags) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool script_push(void *env) {
|
||||
array_push(Ls, L = env);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool script_pop() {
|
||||
L = array_count(Ls) && (array_pop(Ls), array_count(Ls)) ? *array_back(Ls) : NULL;
|
||||
return !!array_count(Ls);
|
||||
}
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_file.c"
|
||||
|
|
20
engine/v4k.h
20
engine/v4k.h
|
@ -1999,7 +1999,15 @@ API void* dll(const char *filename, const char *symbol);
|
|||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
API void script_init();
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void script_init(); // @deprecate
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_push(void *env);
|
||||
|
||||
API void script_run(const char *script);
|
||||
API void script_runfile(const char *pathfile);
|
||||
|
||||
|
@ -2009,15 +2017,7 @@ API void script_call(const char *lua_function);
|
|||
|
||||
API bool script_tests();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
};
|
||||
|
||||
API void *script_init_env(unsigned flags);
|
||||
API bool script_pop();
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_file.h"
|
||||
|
|
Loading…
Reference in New Issue