Implementing async api
This commit is contained in:
@@ -54,10 +54,13 @@ const char *KRContext::extension_names[KRENGINE_NUM_EXTENSIONS] = {
|
||||
KRContext::log_callback *KRContext::s_log_callback = NULL;
|
||||
void *KRContext::s_log_callback_user_data = NULL;
|
||||
|
||||
KRContext::KRContext()
|
||||
KRContext::KRContext(const KrInitializeInfo* initializeInfo)
|
||||
: m_streamer(*this)
|
||||
, m_vulkanInstance(VK_NULL_HANDLE)
|
||||
, m_resourceMapSize(initializeInfo->resourceMapSize)
|
||||
{
|
||||
m_resourceMap = (KRResource **)malloc(sizeof(KRResource*) * m_resourceMapSize);
|
||||
memset(m_resourceMap, 0, m_resourceMapSize * sizeof(KRResource*));
|
||||
m_streamingEnabled = false;
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info(&m_timebase_info);
|
||||
@@ -103,7 +106,6 @@ KRContext::KRContext()
|
||||
}
|
||||
|
||||
KRContext::~KRContext() {
|
||||
|
||||
if(m_pSceneManager) {
|
||||
delete m_pSceneManager;
|
||||
m_pSceneManager = NULL;
|
||||
@@ -156,6 +158,10 @@ KRContext::~KRContext() {
|
||||
}
|
||||
|
||||
destroyDeviceContexts();
|
||||
if (m_resourceMap) {
|
||||
delete m_resourceMap;
|
||||
m_resourceMap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void KRContext::SetLogCallback(log_callback *log_callback, void *user_data)
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
static int KRENGINE_SYS_PAGE_SIZE;
|
||||
|
||||
|
||||
KRContext();
|
||||
KRContext(const KrInitializeInfo* initializeInfo);
|
||||
~KRContext();
|
||||
|
||||
void loadResource(const std::string &file_name, KRDataBlock *data);
|
||||
@@ -112,6 +112,9 @@ private:
|
||||
KRAnimationCurveManager *m_pAnimationCurveManager;
|
||||
KRAudioManager *m_pSoundManager;
|
||||
KRUnknownManager *m_pUnknownManager;
|
||||
|
||||
KRResource** m_resourceMap;
|
||||
size_t m_resourceMapSize;
|
||||
|
||||
void detectExtensions();
|
||||
bool m_bDetectedExtensions;
|
||||
|
||||
@@ -11,7 +11,7 @@ KRContext* sContext = nullptr;
|
||||
KrResult KrInitialize(const KrInitializeInfo* pInitializeInfo)
|
||||
{
|
||||
if (!sContext) {
|
||||
sContext = new KRContext();
|
||||
sContext = new KRContext(pInitializeInfo);
|
||||
}
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
@@ -33,3 +33,33 @@ KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo)
|
||||
sContext->loadResource(pLoadResourceInfo->pResourcePath);
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
|
||||
KrResult KrUnloadResource(const KrUnloadResourceInfo* pUnloadResourceInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
KrResult KrSaveResource(const KrSaveResourceInfo* pSaveResourceInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
KrResult KrMapResource(const KrMapResourceInfo* pMapResourceInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
KrResult KrUnmapResource(const KrUnmapResourceInfo* pUnmapResourceInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo)
|
||||
{
|
||||
return KR_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -38,29 +38,79 @@
|
||||
typedef enum {
|
||||
KR_SUCCESS = 0,
|
||||
KR_ERROR_NOT_INITIALIZED = 1,
|
||||
KR_ERROR_WRONG_THREAD = 2,
|
||||
KR_ERROR_NOT_IMPLEMENTED = 2,
|
||||
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
} KrResult;
|
||||
|
||||
typedef enum {
|
||||
KR_STRUCTURE_TYPE_INITIALIZE = 0,
|
||||
KR_STRUCTURE_TYPE_SHUTDOWN = 1,
|
||||
KR_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
KR_STRUCTURE_TYPE_INITIALIZE = 0,
|
||||
KR_STRUCTURE_TYPE_SHUTDOWN = 1,
|
||||
KR_STRUCTURE_TYPE_LOAD_RESOURCE = 0x00010000,
|
||||
KR_STRUCTURE_TYPE_UNLOAD_RESOURCE = 0x00010001,
|
||||
KR_STRUCTURE_TYPE_SAVE_RESOURCE = 0x00010002,
|
||||
KR_STRUCTURE_TYPE_MAP_RESOURCE = 0x00010003,
|
||||
KR_STRUCTURE_TYPE_UNMAP_RESOURCE = 0x00010004,
|
||||
KR_STRUCTURE_TYPE_CREATE_BUNDLE = 0x00010005,
|
||||
KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE = 0x00010006,
|
||||
|
||||
KR_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
} KrStructureType;
|
||||
|
||||
typedef int KrResourceMapIndex;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
void* pNext;
|
||||
size_t resourceMapSize;
|
||||
} KrInitializeInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
void* pNext;
|
||||
const char* pResourcePath;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrLoadResourceInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrUnloadResourceInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
const char* presourceName;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrMapResourceInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrUnmapResourceInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
const char* pResourcePath;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrSaveResourceInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
const char* pBundleName;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
} KrCreateBundleInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
KrResourceMapIndex resourceHandle;
|
||||
KrResourceMapIndex bundleHandle;
|
||||
} KrMoveToBundleInfo;
|
||||
|
||||
KrResult KrInitialize(const KrInitializeInfo* pInitializeInfo);
|
||||
KrResult KrShutdown();
|
||||
KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo);
|
||||
KrResult KrUnloadResource(const KrUnloadResourceInfo* pUnloadResourceInfo);
|
||||
KrResult KrSaveResource(const KrSaveResourceInfo* pSaveResourceInfo);
|
||||
KrResult KrMapResource(const KrMapResourceInfo* pMapResourceInfo);
|
||||
KrResult KrUnmapResource(const KrUnmapResourceInfo* pUnmapResourceInfo);
|
||||
KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo);
|
||||
KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo);
|
||||
|
||||
#endif // KRAKEN_H
|
||||
|
||||
@@ -7,8 +7,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
Context* context = Context::Get();
|
||||
|
||||
MSG msg = { 0 };
|
||||
WNDCLASS wc = { 0 };
|
||||
wc.lpfnWndProc = WndProc;
|
||||
|
||||
@@ -11,14 +11,31 @@ int main( int argc, char *argv[] )
|
||||
printf("Initializing Kraken...\n");
|
||||
KrInitializeInfo init_info = {};
|
||||
init_info.sType = KR_STRUCTURE_TYPE_INITIALIZE;
|
||||
init_info.pNext = NULL;
|
||||
init_info.resourceMapSize = 1024;
|
||||
KrResult res = KrInitialize(&init_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("Failed to initialize Kraken!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
KrCreateBundleInfo create_bundle_info = {};
|
||||
create_bundle_info.sType = KR_STRUCTURE_TYPE_CREATE_BUNDLE;
|
||||
create_bundle_info.resourceHandle = 0;
|
||||
create_bundle_info.pBundleName = "output";
|
||||
res = KrCreateBundle(&create_bundle_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("Failed to create bundle.\n");
|
||||
KrShutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
KrLoadResourceInfo load_resource_info = {};
|
||||
load_resource_info.sType = KR_STRUCTURE_TYPE_LOAD_RESOURCE;
|
||||
load_resource_info.resourceHandle = 1;
|
||||
|
||||
KrMoveToBundleInfo move_to_bundle_info = {};
|
||||
move_to_bundle_info.sType = KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE;
|
||||
move_to_bundle_info.bundleHandle = 0;
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
char *arg = argv[i];
|
||||
@@ -28,9 +45,23 @@ int main( int argc, char *argv[] )
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("Failed to load resource: %s\n", arg);
|
||||
}
|
||||
move_to_bundle_info.resourceHandle = 1;
|
||||
res = KrMoveToBundle(&move_to_bundle_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("Failed to move resource to bundle.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KrSaveResourceInfo save_resource_info = {};
|
||||
save_resource_info.sType = KR_STRUCTURE_TYPE_SAVE_RESOURCE;
|
||||
save_resource_info.resourceHandle = 0;
|
||||
save_resource_info.pResourcePath = "output.krbundle";
|
||||
res = KrSaveResource(&save_resource_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("Failed to save bundle.\n");
|
||||
}
|
||||
|
||||
KrShutdown();
|
||||
/*
|
||||
Context* context = Context::Get();
|
||||
|
||||
Reference in New Issue
Block a user