mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
call budget progress
This commit is contained in:
parent
f6f6fb89fd
commit
5dd6f77cc4
@ -84,6 +84,10 @@ bool nn_invokeComponentMethod(nn_component *component, const char *name) {
|
||||
for(size_t i = 0; i < table->methodCount; i++) {
|
||||
nn_method method = table->methods[i];
|
||||
if(strcmp(method.name, name) == 0) {
|
||||
nn_callCost(component->computer, NN_CALL_COST);
|
||||
if(!method.direct) {
|
||||
nn_busySleep(NN_INDIRECT_CALL_LATENCY);
|
||||
}
|
||||
method.method(component->statePtr, method.userdata, component, component->computer);
|
||||
return true;
|
||||
}
|
||||
|
@ -62,6 +62,7 @@
|
||||
#define NN_CALL_HEAT 0.05
|
||||
#define NN_CALL_COST 1
|
||||
#define NN_LABEL_SIZE 128
|
||||
#define NN_INDIRECT_CALL_LATENCY 0.05
|
||||
|
||||
typedef struct nn_guard nn_guard;
|
||||
typedef struct nn_universe nn_universe;
|
||||
@ -144,6 +145,8 @@ void nn_deleteGuard(nn_guard *guard);
|
||||
|
||||
double nn_realTime();
|
||||
double nn_realTimeClock(void *_);
|
||||
/* Will busy-loop until the time passes. This is meant for computed latencies in components. */
|
||||
void nn_busySleep(double t);
|
||||
|
||||
typedef double nn_clock_t(void *_);
|
||||
|
||||
|
@ -205,6 +205,12 @@ static int testLuaArch_computer_setArchitecture(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int testLuaArch_computer_isOverworked(lua_State *L) {
|
||||
nn_computer *c = testLuaArch_getComputer(L);
|
||||
lua_pushboolean(L, nn_isOverworked(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int testLuaArch_computer_isOverheating(lua_State *L) {
|
||||
nn_computer *c = testLuaArch_getComputer(L);
|
||||
lua_pushboolean(L, nn_isOverheating(c));
|
||||
@ -426,6 +432,8 @@ void testLuaArch_loadEnv(lua_State *L) {
|
||||
lua_setfield(L, computer, "getArchitectures");
|
||||
lua_pushcfunction(L, testLuaArch_computer_setArchitecture);
|
||||
lua_setfield(L, computer, "setArchitecture");
|
||||
lua_pushcfunction(L, testLuaArch_computer_isOverworked);
|
||||
lua_setfield(L, computer, "isOverworked");
|
||||
lua_pushcfunction(L, testLuaArch_computer_isOverheating);
|
||||
lua_setfield(L, computer, "isOverheating");
|
||||
lua_pushcfunction(L, testLuaArch_computer_getTemperature);
|
||||
|
@ -59,3 +59,8 @@ double nn_realTime() {
|
||||
double nn_realTimeClock(void *_) {
|
||||
return nn_realTime();
|
||||
}
|
||||
|
||||
void nn_busySleep(double t) {
|
||||
double deadline = nn_realTime() + t;
|
||||
while(nn_realTime() < deadline) {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user