Source

dark-hammer / src / engine / engine.c

The branch '0.4.7' does not exist.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/***********************************************************************************
 * Copyright (c) 2012, 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.
 *
 ***********************************************************************************/

#include <stdio.h>

#include "engine.h"
#include "core/core.h"
#include "core/timer.h"
#include "core/json.h"
#include "core/pak-file.h"
#include "core/freelist-alloc.h"

#include "mem-ids.h"
#include "gfx.h"
#include "hwinfo.h"
#include "core/file-mgr.h"
#include "core/stack-alloc.h"
#include "res-mgr.h"
#include "input.h"
#include "debug-hud.h"
#include "console.h"
#include "prf-mgr.h"
#include "cmp-mgr.h"
#include "scene-mgr.h"
#include "script.h"
#include "gfx-canvas.h"
#include "gfx-cmdqueue.h"
#include "lod-scheme.h"
#include "phx.h"
#include "app.h"

#define GRAPH_WIDTH 250
#define GRAPH_HEIGHT 100

#define FRAME_STACK_SIZE (8*1024*1024)
#define DATA_SIZE (8*1024*1024)
#define LSR_SIZE (128*1024)

/*************************************************************************************************
 * types 
 */
struct engine
{
    struct pak_file data_pak;   /* only loaded in release mode */
    struct init_params params;
    struct frame_stats frame_stats;
    struct timer* timer;
    bool_t simulate_mode;
    bool_t init;
    struct hwinfo hwinfo;

    struct allocator frame_alloc;
    struct stack_alloc frame_stack;

    struct allocator data_alloc;
    struct stack_alloc data_stack;
    struct freelist_alloc data_freelist;

    struct allocator lsr_alloc;
    struct stack_alloc lsr_stack;

    uint32 alloc_tmp0_frameid;  /* maximum tmp allocated frameid */
    uint32 alloc_tmp0_max; /* maxomum allocated bytes from temp0 stack allocator */
    int32 fps_lock;    /* =0 if not locked */
};

/*************************************************************************************************/
/* engine global */
struct engine g_eng;

/*************************************************************************************************
 * fwd declarations
 */
void eng_world_initvars();
result_t eng_console_showfps(uint32 argc, const char ** argv, void* param);
result_t eng_console_showft(uint32 argc, const char ** argv, void* param);
result_t eng_console_showgraph(uint32 argc, const char ** argv, void* param);
result_t eng_console_lockfps(uint32 argc, const char** argv, void* param);

int32 eng_hud_drawcallgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y, bool_t update, 
    void* param);
int32 eng_hud_drawftgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y, bool_t update,
    void* param);
int32 eng_hud_drawfpsgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y, bool_t update,
    void* param);
int32 eng_hud_drawfps(gfx_cmdqueue cmdqueue, int32 x, int32 y, int32 line_stride, void* param);
int32 eng_hud_drawft(gfx_cmdqueue cmdqueue, int32 x, int32 y, int32 line_stride, void* param);

/*************************************************************************************************/
void eng_zero()
{
    memset(&g_eng, 0x00, sizeof(struct engine));
    gfx_zero();
    rs_zero();
    con_zero();
    hud_zero();
    sct_zero();
    lod_zero();
    input_zero();

#if defined(_PROFILE_)
    prf_zero();
#endif
    phx_zero();
}

result_t eng_init(const struct init_params* params)
{
    result_t r;

    memcpy(&g_eng.params, params, sizeof(struct init_params));

    hw_getinfo(&g_eng.hwinfo, HWINFO_CPU);

    /* console (before anything else) */
    if (BIT_CHECK(params->flags, ENG_FLAG_CONSOLE))	{
		r = con_init(params->console_lines_max);
		if (IS_FAIL(r))
			return RET_FAIL;
		log_outputfunc(TRUE, con_log, NULL);
    }

    /* show build options */
#if !defined(FULL_VERSION)
#error "must define FULL_VERSION macro"
#endif

    log_printf(LOG_TEXT, "init dark-hammer engine v%s build[%s, %s, %s, %s] ...", FULL_VERSION,
#if defined(_DEBUG_)
    		"debug"
#else
    		"release"
#endif
    		,
#if defined(_PROFILE_)
    		"profile"
#else
    		"no-profile"
#endif
    		,
#if defined(_X86_)
    		"x86"
#elif defined(_X64_)
    		"x64"
#endif
    		,
#if defined(_ENABLEASSERT_)
    		"assert"
#else
    		"no-assert"
#endif
    		);

    /* allocators */
    r = mem_stack_create(mem_heap(), &g_eng.frame_stack, FRAME_STACK_SIZE, MID_BASE);

    /* lsr (load-stay-resident) allocator for essential engine data */
    r |= mem_stack_create(mem_heap(), &g_eng.lsr_stack, LSR_SIZE, MID_DATA);
    mem_stack_bindalloc(&g_eng.lsr_stack, &g_eng.lsr_alloc);

    /* dynamic allocator for data in dev (editor) mode, stack allocator in game (normal) mode */
    if (BIT_CHECK(params->flags, ENG_FLAG_DEV)) {
        r |= mem_freelist_create(mem_heap(), &g_eng.data_freelist, DATA_SIZE, MID_DATA);
        mem_freelist_bindalloc(&g_eng.data_freelist, &g_eng.data_alloc);
    }   else    {
        r |= mem_stack_create(mem_heap(), &g_eng.data_stack, DATA_SIZE, MID_DATA);
        mem_stack_bindalloc(&g_eng.data_stack, &g_eng.data_alloc);
    }

    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: out of memory for allocators");
        return RET_FAIL;
    }
    mem_stack_bindalloc(&g_eng.frame_stack, &g_eng.frame_alloc);

    /* timer manager and frame timer */
    g_eng.timer = timer_add(TRUE);

    /* add engine data path to file-mgr */
#if defined(_DEBUG_)
    char data_path[DH_PATH_MAX];
    util_getexedir(data_path);
    path_join(data_path, path_goup(data_path, data_path), "data", NULL);
    io_addvdir(params->data_dir ? params->data_dir : data_path, FALSE);
#else
    /* try loading pak file */
    char data_path[DH_PATH_MAX];
    util_getexedir(data_path);
    path_join(data_path, path_goup(data_path, data_path), "data.pak", NULL);
    if (IS_FAIL(pak_open(&g_eng.data_pak, mem_heap(), data_path, 0)))   {
        err_clear();
        log_print(LOG_WARNING, "could not locate 'data.pak' switching to local directory");
        /* set local path just like debug mode */
        util_getexedir(data_path);
        path_join(data_path, path_goup(data_path, data_path), "data", NULL);
        io_addvdir(params->data_dir ? params->data_dir : data_path, FALSE);
    }   else    {
        io_addpak(&g_eng.data_pak);
    }
#endif

    /* resource manager */
    uint32 rs_flags = 0;
    if (BIT_CHECK(params->flags, ENG_FLAG_DEV))
        rs_flags |= RS_FLAG_HOTLOADING;
    r = rs_init(rs_flags);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init res-mgr");
        return RET_FAIL;
    }
    rs_set_dataalloc(&g_eng.lsr_alloc);

    /* graphics renderer */
    r = gfx_init(&params->gfx);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init gfx");
        return RET_FAIL;
    }

    /* debug HUD */
    r = hud_init(BIT_CHECK(params->flags, ENG_FLAG_CONSOLE));
    if (IS_FAIL(r))	{
        err_print(__FILE__, __LINE__, "engine init failed: could not init debug-hud");
        return RET_FAIL;
    }

    /* Physics */
    if (!BIT_CHECK(params->flags, ENG_FLAG_DISABLEPHX)) {
        r = phx_init(&params->phx);
        if (IS_FAIL(r)) {
            err_print(__FILE__, __LINE__, "engine init failed: could not init physics");
            return RET_FAIL;
        }
    }

    /* input */
    input_init();

    /* component manager */
    r = cmp_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init cmp-mgr");
        return RET_FAIL;
    }
    cmp_set_globalalloc(&g_eng.data_alloc, &g_eng.frame_alloc);

    /* scene manager */
    r = scn_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init scene-mgr");
        return RET_FAIL;
    }

    /* init lua */
    r = sct_init(&params->sct, BIT_CHECK(params->flags, ENG_FLAG_DEV) ? TRUE : FALSE);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init script engine");
        return RET_FAIL;
    }

    /* web-server */
#if defined(_PROFILE_)
    r = prf_initmgr();
    if (IS_FAIL(r))	{
    	log_print(LOG_WARNING, "profiler manager init failed: service will not be available");
    	prf_releasemgr();
    }
#endif

    /* lod-scheme */
    r = lod_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init lod-scheme");
        return RET_FAIL;
    }

    /* switch back to normal data allocator */
    rs_set_dataalloc(&g_eng.data_alloc);
    log_print(LOG_TEXT, "init ok: ready.");

    /* hardware info */
    hw_getinfo(&g_eng.hwinfo, HWINFO_ALL);
    hw_printinfo(&g_eng.hwinfo, HWINFO_ALL);

    /* init world vars */
    eng_world_initvars();

    /* engine specific console commnads */
    con_register_cmd("showfps", eng_console_showfps, NULL, "showfps [1*/0]");
    con_register_cmd("showft", eng_console_showft, NULL, "showft [1*/0]");
    con_register_cmd("showgraph", eng_console_showgraph, NULL, "showgraph [ft][fps][drawcalls]");
    con_register_cmd("lockfps", eng_console_lockfps, NULL, "lockfps [fps]");

    /* execute console commands - should be the final stage if initialization */
    if (BIT_CHECK(params->flags, ENG_FLAG_CONSOLE))	{
		for (uint32 i = 0; i < params->console_cmds_cnt; i++)	{
			con_exec(params->console_cmds + i*128);
		}
    }

    return RET_OK;
}

void eng_release()
{
    lod_releasemgr();
#if !defined(_DEBUG_)
    pak_close(&g_eng.data_pak);
#endif
	prf_releasemgr();
    sct_release();
    scn_releasemgr();
    cmp_releasemgr();
    input_release();
    phx_release();
    hud_release();
    gfx_release();
    rs_reportleaks();
    rs_release();

    if (g_eng.timer != NULL)
        timer_remove(g_eng.timer);

    /* check for main memory leaks */
    if (BIT_CHECK(g_eng.params.flags, ENG_FLAG_DEV))    {
        uint32 leak_cnt = mem_freelist_getleaks(&g_eng.data_freelist, NULL);
        if (leak_cnt > 0)
            log_printf(LOG_WARNING, "%d leaks found on dynamic 'data' memory", leak_cnt);
    }

    mem_stack_destroy(&g_eng.frame_stack);
    mem_freelist_destroy(&g_eng.data_freelist);
    mem_stack_destroy(&g_eng.data_stack);
    mem_stack_destroy(&g_eng.lsr_stack);

    log_print(LOG_TEXT, "engine released.");

	if (BIT_CHECK(g_eng.params.flags, ENG_FLAG_CONSOLE))	{
		log_outputfunc(FALSE, NULL, NULL);
		con_release();
	}

    eng_zero();
}

void eng_update()
{
    /* variables for fps calculation */
    static fl32 elapsed_tm = 0.0f;
    static uint32 frame_cnt = 0;
    static bool_t simulated = FALSE;

    /* reset frame stack on start of each frame */
    if (g_eng.frame_stack.alloc_max > g_eng.alloc_tmp0_max)    {
        g_eng.alloc_tmp0_max = g_eng.frame_stack.alloc_max;
        g_eng.alloc_tmp0_frameid = g_eng.frame_stats.frame;
    }
    mem_stack_reset(&g_eng.frame_stack);
    
    uint64 start_tick = timer_querytick();
    g_eng.frame_stats.start_tick = start_tick;

    /* check for file changes (dev-mode) */
    if (BIT_CHECK(g_eng.params.flags, ENG_FLAG_DEV))
        io_mon_update();

    /* update all timers */
    timer_update(start_tick);

    /* do all the work ... */
    fl32 dt = g_eng.timer->dt;

    /* physics */
    if (!BIT_CHECK(g_eng.params.flags, ENG_FLAG_DISABLEPHX)) {
        if (simulated)
            phx_wait();
        phx_update_xforms(simulated);   /* gather results */
    }

    /* update scripting */
    sct_update();

    /* physics: run simulation */
    if (!BIT_CHECK(g_eng.params.flags, ENG_FLAG_DISABLEPHX))
        simulated = phx_update_sim(dt);

    /* update component system stages */
    PRF_OPENSAMPLE("Component (pre-render)");
    cmp_update(dt, CMP_UPDATE_STAGE1);
    cmp_update(dt, CMP_UPDATE_STAGE2);
    cmp_update(dt, CMP_UPDATE_STAGE3);
    cmp_update(dt, CMP_UPDATE_STAGE4);
    PRF_CLOSESAMPLE();

    /* cull and render active scene */
    PRF_OPENSAMPLE("Render");
    gfx_render();
    PRF_CLOSESAMPLE();

    PRF_OPENSAMPLE("Component (post-render)");
    cmp_update(dt, CMP_UPDATE_STAGE5);
    PRF_CLOSESAMPLE();

    PRF_OPENSAMPLE("Display");
    app_swapbuffers();
    PRF_CLOSESAMPLE();

    /* clear update list of components */
    cmp_clear_updates();

    /* final frame stats calculation */
    fl64 ft = timer_calctm(start_tick, timer_querytick());
    if (g_eng.fps_lock > 0)  {
        fl64 target_ft = 1.0 / (fl64)g_eng.fps_lock;
        while (ft < target_ft)  {
            ft = timer_calctm(start_tick, timer_querytick());
        }
    }

#if defined(_PROFILE_)
    /* present samples in _PROFILE_ mode */
    prf_presentsamples(ft);
#endif

    g_eng.frame_stats.ft = (fl32)ft;
    g_eng.frame_stats.frame ++;
    frame_cnt ++;
    elapsed_tm += (fl32)ft;
    if (elapsed_tm > 1.0f)  {
        g_eng.frame_stats.fps = frame_cnt;
        frame_cnt = 0;
        elapsed_tm = 0.0f;
    }
}

struct allocator* eng_get_framealloc()
{
    return &g_eng.frame_alloc;
}

void eng_save_framealloc()
{
    mem_stack_save(&g_eng.frame_stack);
}

void eng_load_framealloc()
{
    mem_stack_load(&g_eng.frame_stack);
}

const struct frame_stats* eng_get_framestats()
{
	return &g_eng.frame_stats;
}

void eng_send_guimsgs(char c, uint32 vkey)
{
	hud_send_input(c, input_translate_key(vkey));
}

const struct init_params* eng_get_params()
{
	return &g_eng.params;
}

struct allocator* eng_get_lsralloc()
{
    return &g_eng.lsr_alloc;
}

struct allocator* eng_get_dataalloc()
{
    return &g_eng.data_alloc;
}

void eng_get_memstats(struct eng_mem_stats* stats)
{
    memset(stats, 0x00, sizeof(struct eng_mem_stats));
    if (BIT_CHECK(g_eng.params.flags, ENG_FLAG_DEV))    {
        stats->data_max = g_eng.data_freelist.size;
        stats->data_size = g_eng.data_freelist.alloc_size;
    }   else    {
        stats->data_max = g_eng.data_stack.size;
        stats->data_size = g_eng.data_stack.offset;
    }
    stats->lsr_max = g_eng.lsr_stack.size;
    stats->lsr_size = g_eng.lsr_stack.offset;

    stats->tmp0_total = g_eng.frame_stack.size;
    stats->tmp0_max = g_eng.alloc_tmp0_max;
    stats->tmp0_max_frameid = g_eng.alloc_tmp0_frameid;
}

void eng_world_initvars()
{
    /* add default world vars */
    fl32 sun_dir[3] = {0.0f, -1.0f, 0.5f};
    fl32 sun_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
    fl32 ambient_sky[4] = {0.34f, 0.37f, 0.73f, 1.0f};
    fl32 ambient_ground[4] = {0.29f, 0.45f, 0.32f, 1.0f};
    fl32 sky_vector[3] = {0.0f, 1.0f, 0.0f};
    scn_world_setvar3f("sun_dir", sun_dir);
    scn_world_setvar3f("sun_color", sun_color);
    scn_world_setvarf("sun_intensity", 1.0f);
    scn_world_setvarf("ambient_intensity", 0.2f);
    scn_world_setvar3f("ambient_sky", ambient_sky);
    scn_world_setvar3f("ambient_ground", ambient_ground);
    scn_world_setvar3f("sky_vector", sky_vector);
}

result_t eng_console_showfps(uint32 argc, const char** argv, void* param)
{
    bool_t value = TRUE;
    if (argc == 1)
        value = str_tobool(argv[0]);
    if (value)
        hud_add_label("fps", eng_hud_drawfps, NULL);
    else
        hud_remove_label("fps");

    return RET_OK;
}

result_t eng_console_showft(uint32 argc, const char** argv, void* param)
{
    bool_t value = TRUE;
    if (argc == 1)
        value = str_tobool(argv[0]);
    if (value)
        hud_add_label("ft", eng_hud_drawft, NULL);
    else
        hud_remove_label("ft");

    return RET_OK;
}

int32 eng_hud_drawfps(gfx_cmdqueue cmdqueue, int32 x, int32 y, int32 line_stride, void* param)
{
    const struct frame_stats* stats = eng_get_framestats();
    char text[32];
    sprintf(text, "fps = %d", stats->fps);
    gfx_canvas_text2dpt(text, x, y, 0);
    y += line_stride;
    return y;
}

int32 eng_hud_drawft(gfx_cmdqueue cmdqueue, int32 x, int32 y, int32 line_stride, void* param)
{
    const struct frame_stats* stats = eng_get_framestats();
    char text[32];
    sprintf(text, "ft = %.2f ms", stats->ft*1000.0f);
    gfx_canvas_text2dpt(text, x, y, 0);
    y += line_stride;
    return y;
}

result_t eng_console_showgraph(uint32 argc, const char** argv, void* param)
{
    if (argc != 1 && argc != 2)
        return RET_INVALIDARG;
    bool_t show = TRUE;
    if (argc == 2)
        show = str_tobool(argv[1]);

    struct rect2di rc;

    if (str_isequal_nocase(argv[0], "ft"))	{
        if (show)   {
            hud_add_graph("graph-ft", eng_hud_drawftgraph, ui_create_graphline("ft", 0, 16.0f, 60,
                *rect2di_seti(&rc, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), FALSE), NULL);
        }   else    {
            hud_remove_graph("graph-ft");
        }
    }
    else if (str_isequal_nocase(argv[0], "fps"))	{
        if (show)   {
            hud_add_graph("graph-fps", eng_hud_drawfpsgraph, 
                ui_create_graphline("fps", 0, 60.0f, 60,
                *rect2di_seti(&rc, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), TRUE),NULL);
        }   else    {
            hud_remove_graph("graph-fps");
        }
    }
    else if (str_isequal_nocase(argv[0], "drawcalls"))	{
        if (show)   {
            hud_add_graph("graph-drawcall", eng_hud_drawcallgraph, 
                ui_create_graphline("drawcalls", 0, 100.0f, 60,
                *rect2di_seti(&rc, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), TRUE), NULL);
        }   else    {
            hud_remove_graph("graph-drawcall");
        }
    }
    else    {
        return RET_INVALIDARG;
    }

    return RET_OK;
}

int32 eng_hud_drawfpsgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y, bool_t update,
    void* param)
{
    const struct frame_stats* stats = eng_get_framestats();

    if (update)
        ui_graphline_addvalue(widget, (fl32)stats->fps);

    ui_widget_move(widget, x, y);
    ui_widget_draw(widget);

    return y + GRAPH_HEIGHT;
}

int32 eng_hud_drawftgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y, bool_t update,
    void* param)
{
    const struct frame_stats* stats = eng_get_framestats();
    if (update)
        ui_graphline_addvalue(widget, stats->ft*1000.0f);

    ui_widget_move(widget, x, y);
    ui_widget_draw(widget);

    return y + GRAPH_HEIGHT;
}

int32 eng_hud_drawcallgraph(gfx_cmdqueue cmdqueue, ui_widget widget, int32 x, int32 y,
    bool_t update, void* param)
{
    const struct gfx_framestats* stats = gfx_get_framestats(cmdqueue);
    if (update)
        ui_graphline_addvalue(widget, (fl32)stats->draw_cnt);
    ui_widget_move(widget, x, y);
    ui_widget_draw(widget);

    return y + GRAPH_HEIGHT;
}

const struct hwinfo* eng_get_hwinfo()
{
    return &g_eng.hwinfo;
}

result_t eng_console_lockfps(uint32 argc, const char** argv, void* param)
{
    if (argc != 1)
        return RET_INVALIDARG;

    g_eng.fps_lock = clampun(str_toint32(argv[0]), 0, 1000);
    return RET_OK;
}

void eng_pause()
{
    timer_pauseall();
}


void eng_resume()
{
    timer_resumeall();
}
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.