Adding language

This commit is contained in:
2024-10-16 14:37:34 -07:00
parent 6c062df9bb
commit 3baafec9cb
17 changed files with 451 additions and 0 deletions

View File

@ -4,6 +4,7 @@
# https://opensource.org/licenses/MIT
# Subdirs
add_subdirectory(conversation)
add_subdirectory(entity)
add_subdirectory(world)

View File

@ -0,0 +1,13 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirs
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
conversation.c
testconversation.c
)

View File

@ -0,0 +1,74 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "conversation.h"
#include "assert/assert.h"
void conversationInit(
conversation_t *conversation,
const conversationcallback_t init,
const conversationcallback_t update
) {
assertNotNull(conversation, "Conversation is NULL.");
memset(conversation, 0, sizeof(conversation_t));
conversation->init = init;
conversation->update = update;
conversation->index = CONVERSATION_NOT_INITIALIZED;
}
void conversationUpdate(conversation_t *conversation) {
uint16_t ret;
assertNotNull(conversation, "Conversation is NULL.");
// Init or update.
switch(conversation->index) {
case CONVERSATION_NOT_INITIALIZED:
conversation->index = 0;
ret = conversation->init(
conversation, conversation->index
);
break;
default:
ret = conversation->update(conversation, conversation->index);
break;
}
// Check ret value and update conversation.
switch(ret) {
case CONVERSATION_NEXT:
conversation->index++;
conversation->index = conversation->init(
conversation, conversation->index
);
break;
case CONVERSATION_CONTINUE:
return;
case CONVERSATION_RESTART:
conversation->index = 0;
conversation->init(conversation, conversation->index);
break;
case CONVERSATION_INVALID:
assertUnreachable("Invalid converstaion retval");
break;
case CONVERSATION_DONE:
break;
default:
conversation->index = ret;
conversation->index = conversation->init(
conversation, conversation->index
);
break;
}
}

View File

@ -0,0 +1,48 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawn.h"
#define CONVERSATION_NEXT ((uint16_t)-1)
#define CONVERSATION_CONTINUE ((uint16_t)-2)
#define CONVERSATION_NOT_INITIALIZED ((uint16_t)-3)
#define CONVERSATION_RESTART CONVERSATION_NOT_INITIALIZED
#define CONVERSATION_DONE ((uint16_t)-4)
#define CONVERSATION_INVALID ((uint16_t)-5)
typedef struct _conversation_t conversation_t;
typedef uint16_t (*conversationcallback_t) (
conversation_t *convo, const uint16_t
);
typedef struct _conversation_t {
uint16_t index;
conversationcallback_t init;
conversationcallback_t update;
void *user;
} conversation_t;
/**
* Initializes a conversation object.
*
* @param conversation Conversation to initialize.
* @param update Function to handle conversation updates.
*/
void conversationInit(
conversation_t *conversation,
const conversationcallback_t init,
const conversationcallback_t update
);
/**
* Update a given conversation.
*
* @param conversastion Conversation to update.
*/
void conversationUpdate(conversation_t *conversation);

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "testconversation.h"
uint16_t conversationTestInit(conversation_t *convo, const uint16_t i) {
switch(i) {
case 0:
printf("Test conversation start\n");
return CONVERSATION_CONTINUE;
default:
return CONVERSATION_INVALID;
}
}
uint16_t conversationTestUpdate(conversation_t *convo, const uint16_t i) {
switch(i) {
case 0:
printf("Conversation update\n");
return CONVERSATION_DONE;
default:
return CONVERSATION_INVALID;
}
}

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "conversation.h"
uint16_t conversationTestInit(conversation_t *convo, const uint16_t i);
uint16_t conversationTestUpdate(conversation_t *convo, const uint16_t i);