Reg console.
This commit is contained in:
+4
-1
@@ -16,6 +16,7 @@ if PSP then
|
|||||||
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
||||||
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
||||||
inputBind("lstick_right", INPUT_ACTION_RIGHT)
|
inputBind("lstick_right", INPUT_ACTION_RIGHT)
|
||||||
|
inputBind("triangle", INPUT_ACTION_CONSOLE)
|
||||||
|
|
||||||
elseif DOLPHIN then
|
elseif DOLPHIN then
|
||||||
inputBind("up", INPUT_ACTION_UP)
|
inputBind("up", INPUT_ACTION_UP)
|
||||||
@@ -24,7 +25,8 @@ elseif DOLPHIN then
|
|||||||
inputBind("right", INPUT_ACTION_RIGHT)
|
inputBind("right", INPUT_ACTION_RIGHT)
|
||||||
inputBind("b", INPUT_ACTION_CANCEL)
|
inputBind("b", INPUT_ACTION_CANCEL)
|
||||||
inputBind("a", INPUT_ACTION_ACCEPT)
|
inputBind("a", INPUT_ACTION_ACCEPT)
|
||||||
inputBind("z", INPUT_ACTION_RAGEQUIT)
|
-- inputBind("z", INPUT_ACTION_RAGEQUIT)
|
||||||
|
inputBind("z", INPUT_ACTION_CONSOLE)
|
||||||
inputBind("lstick_up", INPUT_ACTION_UP)
|
inputBind("lstick_up", INPUT_ACTION_UP)
|
||||||
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
||||||
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
||||||
@@ -48,6 +50,7 @@ elseif LINUX then
|
|||||||
inputBind("q", INPUT_ACTION_CANCEL)
|
inputBind("q", INPUT_ACTION_CANCEL)
|
||||||
|
|
||||||
inputBind("escape", INPUT_ACTION_RAGEQUIT)
|
inputBind("escape", INPUT_ACTION_RAGEQUIT)
|
||||||
|
inputBind("`", INPUT_ACTION_CONSOLE)
|
||||||
end
|
end
|
||||||
|
|
||||||
if INPUT_GAMEPAD then
|
if INPUT_GAMEPAD then
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
void cmdToggleConsole(const consolecmdexec_t *exec) {
|
void cmdTime(const consolecmdexec_t *exec) {
|
||||||
CONSOLE.visible = !CONSOLE.visible;
|
consolePrint("Time: %.2f", TIME.time);
|
||||||
}
|
}
|
||||||
+49
-17
@@ -18,6 +18,8 @@
|
|||||||
#include "console/cmd/cmdget.h"
|
#include "console/cmd/cmdget.h"
|
||||||
#include "console/cmd/cmdquit.h"
|
#include "console/cmd/cmdquit.h"
|
||||||
#include "console/cmd/cmdbind.h"
|
#include "console/cmd/cmdbind.h"
|
||||||
|
#include "console/cmd/cmdtime.h"
|
||||||
|
|
||||||
#include "display/shader/shaderunlit.h"
|
#include "display/shader/shaderunlit.h"
|
||||||
#include "display/text/text.h"
|
#include "display/text/text.h"
|
||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
@@ -28,9 +30,11 @@ void consoleInit() {
|
|||||||
memoryZero(&CONSOLE, sizeof(console_t));
|
memoryZero(&CONSOLE, sizeof(console_t));
|
||||||
|
|
||||||
// Register vars
|
// Register vars
|
||||||
consoleRegVar("fps", "0", NULL);
|
#define REG(name, value) consoleRegVar(name, value, NULL)
|
||||||
|
REG("console", "0");
|
||||||
|
#undef REG
|
||||||
|
|
||||||
// Register cmds
|
// Register cmdss
|
||||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||||
|
|
||||||
@@ -39,6 +43,7 @@ void consoleInit() {
|
|||||||
REG("quit", cmdQuit);
|
REG("quit", cmdQuit);
|
||||||
REG("exit", cmdQuit);
|
REG("exit", cmdQuit);
|
||||||
REG("bind", cmdBind);
|
REG("bind", cmdBind);
|
||||||
|
REG("time", cmdTime);
|
||||||
#undef REG
|
#undef REG
|
||||||
|
|
||||||
#ifdef DUSK_CONSOLE_POSIX
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
@@ -86,6 +91,31 @@ consolevar_t * consoleVarGet(const char_t *name) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t consoleVarGetInt(const char_t *name, const int32_t initial) {
|
||||||
|
consolevar_t *var = consoleVarGet(name);
|
||||||
|
if(var == NULL) return initial;
|
||||||
|
char *end;
|
||||||
|
int32_t value = (int32_t)strtol(var->value, &end, 10);
|
||||||
|
if(*end != '\0') return initial;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t consoleVarGetBool(const char_t *name, const bool_t initial) {
|
||||||
|
return consoleVarGetInt(name, initial ? 1 : 0) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void consoleVarSetInt(const char_t *name, const int32_t value) {
|
||||||
|
consolevar_t *existing = consoleVarGet(name);
|
||||||
|
assertNotNull(existing, "Variable not found");
|
||||||
|
char_t buffer[CONSOLE_VAR_VALUE_MAX];
|
||||||
|
stringFormat(buffer, CONSOLE_VAR_VALUE_MAX, "%d", value);
|
||||||
|
consoleVarSetValue(existing, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void consoleVarSetBool(const char_t *name, const bool_t value) {
|
||||||
|
consoleVarSetInt(name, value ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
void consolePrint(const char_t *message, ...) {
|
void consolePrint(const char_t *message, ...) {
|
||||||
char_t buffer[CONSOLE_LINE_MAX];
|
char_t buffer[CONSOLE_LINE_MAX];
|
||||||
|
|
||||||
@@ -337,14 +367,18 @@ void consoleExec(const char_t *line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void consoleUpdate() {
|
void consoleUpdate() {
|
||||||
|
#ifdef DUSK_TIME_DYNAMIC
|
||||||
|
if(TIME.dynamicUpdate) return;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DUSK_CONSOLE_POSIX
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
threadMutexLock(&CONSOLE.execMutex);
|
threadMutexLock(&CONSOLE.execMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Toggle console
|
// Toggle console
|
||||||
// if(inputPressed(INPUT_ACTION_CONSOLE)) {
|
if(inputPressed(INPUT_ACTION_CONSOLE)) {
|
||||||
// CONSOLE.visible = !CONSOLE.visible;
|
consoleVarSetBool("console", !consoleVarGetBool("console", false));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Anything to exec?
|
// Anything to exec?
|
||||||
if(CONSOLE.execBufferCount == 0) {
|
if(CONSOLE.execBufferCount == 0) {
|
||||||
@@ -379,21 +413,19 @@ void consoleUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorret_t consoleDraw() {
|
errorret_t consoleDraw() {
|
||||||
if(!CONSOLE.visible) {
|
if(!consoleVarGetBool("console", false)) {
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorChain(shaderSetTexture(
|
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
||||||
&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &DEFAULT_FONT_TEXTURE
|
errorChain(textDraw(
|
||||||
));
|
0, DEFAULT_FONT_TILESET.tileHeight * i,
|
||||||
errorChain(shaderSetColor(&SHADER_UNLIT, SHADER_UNLIT_COLOR, COLOR_WHITE));
|
CONSOLE.line[i],
|
||||||
errorChain(textDraw(
|
COLOR_WHITE,
|
||||||
32, 32,
|
&DEFAULT_FONT_TILESET,
|
||||||
"Hello World",
|
&DEFAULT_FONT_TEXTURE
|
||||||
COLOR_WHITE,
|
));
|
||||||
&DEFAULT_FONT_TILESET,
|
}
|
||||||
&DEFAULT_FONT_TEXTURE
|
|
||||||
));
|
|
||||||
errorChain(spriteBatchFlush());
|
errorChain(spriteBatchFlush());
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ typedef struct {
|
|||||||
consolecmd_t *cmdGet;
|
consolecmd_t *cmdGet;
|
||||||
consolecmd_t *cmdSet;
|
consolecmd_t *cmdSet;
|
||||||
|
|
||||||
bool_t visible;
|
|
||||||
|
|
||||||
#ifdef DUSK_CONSOLE_POSIX
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
char_t inputBuffer[CONSOLE_LINE_MAX];
|
char_t inputBuffer[CONSOLE_LINE_MAX];
|
||||||
thread_t thread;
|
thread_t thread;
|
||||||
@@ -94,6 +92,42 @@ consolevar_t * consoleRegVar(
|
|||||||
*/
|
*/
|
||||||
consolevar_t * consoleVarGet(const char_t *name);
|
consolevar_t * consoleVarGet(const char_t *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of a console variable as an int32_t.
|
||||||
|
*
|
||||||
|
* @param name The name of the variable.
|
||||||
|
* @param initial The default value to return if the variable is not found or
|
||||||
|
* invalid.
|
||||||
|
* @return The value of the variable, or default if not found or invalid.
|
||||||
|
*/
|
||||||
|
int32_t consoleVarGetInt(const char_t *name, const int32_t initial);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of a console variable as a bool_t.
|
||||||
|
*
|
||||||
|
* @param name The name of the variable.
|
||||||
|
* @param initial The default value to return if the variable is not found or
|
||||||
|
* invalid.
|
||||||
|
* @return The value of the variable, or default if not found or invalid.
|
||||||
|
*/
|
||||||
|
bool_t consoleVarGetBool(const char_t *name, const bool_t initial);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a console variable as an int32_t.
|
||||||
|
*
|
||||||
|
* @param name The name of the variable.
|
||||||
|
* @param value The new value of the variable.
|
||||||
|
*/
|
||||||
|
void consoleVarSetInt(const char_t *name, const int32_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a console variable as a bool_t.
|
||||||
|
*
|
||||||
|
* @param name The name of the variable.
|
||||||
|
* @param value The new value of the variable.
|
||||||
|
*/
|
||||||
|
void consoleVarSetBool(const char_t *name, const bool_t value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a message to the console.
|
* Prints a message to the console.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,5 +18,5 @@
|
|||||||
#define CONSOLE_ALIAS_MAX 32
|
#define CONSOLE_ALIAS_MAX 32
|
||||||
|
|
||||||
#define CONSOLE_VAR_NAME_MAX 32
|
#define CONSOLE_VAR_NAME_MAX 32
|
||||||
#define CONSOLE_VAR_VALUE_MAX 128
|
#define CONSOLE_VAR_VALUE_MAX 32
|
||||||
#define CONSOLE_VAR_EVENTS_MAX 8
|
#define CONSOLE_VAR_EVENTS_MAX 8
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ LEFT,
|
|||||||
RIGHT,
|
RIGHT,
|
||||||
ACCEPT,
|
ACCEPT,
|
||||||
CANCEL,
|
CANCEL,
|
||||||
RAGEQUIT
|
RAGEQUIT,
|
||||||
|
CONSOLE,
|
||||||
POINTERX,
|
POINTERX,
|
||||||
POINTERY,
|
POINTERY,
|
||||||
|
+65
-62
@@ -41,76 +41,80 @@ errorret_t sceneRender(void) {
|
|||||||
entityid_t camCount = componentGetEntitiesWithComponent(
|
entityid_t camCount = componentGetEntitiesWithComponent(
|
||||||
COMPONENT_TYPE_CAMERA, camEnts, camComps
|
COMPONENT_TYPE_CAMERA, camEnts, camComps
|
||||||
);
|
);
|
||||||
if(camCount == 0) errorOk();
|
|
||||||
|
|
||||||
// Get meshes
|
|
||||||
entityid_t meshEnts[ENTITY_COUNT_MAX];
|
|
||||||
componentid_t meshComps[ENTITY_COUNT_MAX];
|
|
||||||
entityid_t meshCount = componentGetEntitiesWithComponent(
|
|
||||||
COMPONENT_TYPE_MESH, meshEnts, meshComps
|
|
||||||
);
|
|
||||||
if(meshCount == 0) errorOk();
|
|
||||||
|
|
||||||
// Prep Matricies
|
// Prep Matricies
|
||||||
mat4 view, proj, model;
|
mat4 view, proj, model;
|
||||||
errorChain(shaderBind(&SHADER_UNLIT));
|
|
||||||
|
|
||||||
// For each camera.
|
if(camCount > 0) {
|
||||||
for(entityid_t camIndex = 0; camIndex < camCount; camIndex++) {
|
// Get meshes
|
||||||
entityid_t camEnt = camEnts[camIndex];
|
entityid_t meshEnts[ENTITY_COUNT_MAX];
|
||||||
componentid_t camComp = camComps[camIndex];
|
componentid_t meshComps[ENTITY_COUNT_MAX];
|
||||||
componentid_t camPos = entityGetComponent(camEnt, COMPONENT_TYPE_POSITION);
|
entityid_t meshCount = componentGetEntitiesWithComponent(
|
||||||
if(camPos == 0xFF) {
|
COMPONENT_TYPE_MESH, meshEnts, meshComps
|
||||||
logError("Camera entity without entity position found\n");
|
);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
entityCameraGetProjection(camEnt, camComp, proj);
|
if(meshCount > 0) {
|
||||||
entityPositionGetTransform(camEnt, camPos, view);
|
errorChain(shaderBind(&SHADER_UNLIT));
|
||||||
|
|
||||||
// For each mesh.
|
// For each camera.
|
||||||
for(entityid_t meshIndex = 0; meshIndex < meshCount; meshIndex++) {
|
for(entityid_t camIndex = 0; camIndex < camCount; camIndex++) {
|
||||||
entityid_t meshEnt = meshEnts[meshIndex];
|
entityid_t camEnt = camEnts[camIndex];
|
||||||
|
componentid_t camComp = camComps[camIndex];
|
||||||
|
componentid_t camPos = entityGetComponent(camEnt, COMPONENT_TYPE_POSITION);
|
||||||
|
if(camPos == 0xFF) {
|
||||||
|
logError("Camera entity without entity position found\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
componentid_t meshComp = meshComps[meshIndex];
|
entityCameraGetProjection(camEnt, camComp, proj);
|
||||||
mesh_t *mesh = entityMeshGetMesh(meshEnt, meshComp);
|
entityPositionGetTransform(camEnt, camPos, view);
|
||||||
if(mesh == NULL) {
|
|
||||||
continue;
|
// For each mesh.
|
||||||
|
for(entityid_t meshIndex = 0; meshIndex < meshCount; meshIndex++) {
|
||||||
|
entityid_t meshEnt = meshEnts[meshIndex];
|
||||||
|
|
||||||
|
componentid_t meshComp = meshComps[meshIndex];
|
||||||
|
mesh_t *mesh = entityMeshGetMesh(meshEnt, meshComp);
|
||||||
|
if(mesh == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentid_t meshPos = entityGetComponent(
|
||||||
|
meshEnt, COMPONENT_TYPE_POSITION
|
||||||
|
);
|
||||||
|
if(meshPos == 0xFF) {
|
||||||
|
logError("Mesh entity without entity position found\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentid_t meshMat = entityGetComponent(
|
||||||
|
meshEnt, COMPONENT_TYPE_MATERIAL
|
||||||
|
);
|
||||||
|
if(meshMat == 0xFF) {
|
||||||
|
logError("Mesh entity without material component found\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
shadermaterial_t *material = entityMaterialGetShaderMaterial(
|
||||||
|
meshEnt, meshMat
|
||||||
|
);
|
||||||
|
shader_t *shader = entityMaterialGetShader(meshEnt, meshMat);
|
||||||
|
if(shader == NULL) {
|
||||||
|
logError("Mesh entity with material component without shader found\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entityPositionGetTransform(meshEnt, meshPos, model);
|
||||||
|
|
||||||
|
errorChain(shaderBind(shader));
|
||||||
|
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_PROJECTION, proj));
|
||||||
|
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_VIEW, view));
|
||||||
|
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_MODEL, model));
|
||||||
|
errorChain(shaderSetMaterial(shader, material));
|
||||||
|
errorChain(meshDraw(mesh, 0, -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentid_t meshPos = entityGetComponent(
|
|
||||||
meshEnt, COMPONENT_TYPE_POSITION
|
|
||||||
);
|
|
||||||
if(meshPos == 0xFF) {
|
|
||||||
logError("Mesh entity without entity position found\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
componentid_t meshMat = entityGetComponent(
|
|
||||||
meshEnt, COMPONENT_TYPE_MATERIAL
|
|
||||||
);
|
|
||||||
if(meshMat == 0xFF) {
|
|
||||||
logError("Mesh entity without material component found\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
shadermaterial_t *material = entityMaterialGetShaderMaterial(
|
|
||||||
meshEnt, meshMat
|
|
||||||
);
|
|
||||||
shader_t *shader = entityMaterialGetShader(meshEnt, meshMat);
|
|
||||||
if(shader == NULL) {
|
|
||||||
logError("Mesh entity with material component without shader found\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
entityPositionGetTransform(meshEnt, meshPos, model);
|
|
||||||
|
|
||||||
errorChain(shaderBind(shader));
|
|
||||||
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_PROJECTION, proj));
|
|
||||||
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_VIEW, view));
|
|
||||||
errorChain(shaderSetMatrix(shader, SHADER_UNLIT_MODEL, model));
|
|
||||||
errorChain(shaderSetMaterial(shader, material));
|
|
||||||
errorChain(meshDraw(mesh, 0, -1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +137,6 @@ errorret_t sceneRender(void) {
|
|||||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
|
||||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
|
||||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
||||||
|
|
||||||
errorChain(consoleDraw());
|
errorChain(consoleDraw());
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
Reference in New Issue
Block a user