Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Public Member Functions | List of all members
HFCore::ThreadListener Class Referenceabstract

Interface for ThreadListener callback methods. More...

#include <ThreadListener.h>

Public Member Functions

virtual int32_hf threadMain (HF_ThreadInfo *threadInfo)=0
 This method is called just after the thread has been created using Environment::createThread() method. More...

Detailed Description

Interface for ThreadListener callback methods.

Implement listener methods as needed:

#pragma once
#include "hffwk.h"
class GameMain : public HFCore::Game,
typedef struct
int32_hf val1;
int32_hf val2;
} ThreadData;
virtual ~GameMain();
// singleton:
static GameMain *instance();
static void destroy();
// implementation of HFCore::Game:
virtual void init();
virtual void update(fp32_hf dt);
virtual void draw(HFCore::Graphics *g);
// and the rest of methods needed..
// implementation of HFCore::ThreadListener:
virtual void threadMain(HF_ThreadInfo *threadInfo);
// singleton instance:
static GameMain *gInstance;
thread_hf mThreadID;
HF_ThreadInfo *mThreadInfo;
ThreadData *mThreadData;

Spawn a new thread:

// make sure thread is done:
envDebugLog("Waiting for thread to finish...\r\n");
int32_hf threadRetVal = 0;
HFCORE_ENV->waitThread(mThreadID, &threadRetVal);
envDebugLog("Thread return value: %d\r\n", threadRetVal);
// delete thread data:
void GameMain::createThread()
// init data for thread:
mThreadInfo = new HF_ThreadInfo();
assert(mThreadInfo != NULL);
memset(mThreadInfo, 0, sizeof(HF_ThreadInfo));
mThreadData = new ThreadData();
assert(mThreadData != NULL);
memset(mThreadData, 0, sizeof(ThreadData));
mThreadData->val1 = 1001;
mThreadData->val2 = 2002;
mThreadInfo->id = 1;
mThreadInfo->data = (void *)mThreadData;
// spawn a new thread:
mThreadID = HFCORE_ENV->createThread(mThreadInfo, this);
int32_hf GameMain::threadMain(HF_ThreadInfo *threadInfo)
ThreadData *threadData = (ThreadData *)threadInfo->data;
for (int32_hf i = 6; i >= 0; i--)
envDebugLog("threadMain counting down: %d\r\n", i);
return (threadData->val1 + threadData->val2);

Definition at line 123 of file ThreadListener.h.

Member Function Documentation

◆ threadMain()

virtual int32_hf HFCore::ThreadListener::threadMain ( HF_ThreadInfo threadInfo)
pure virtual

This method is called just after the thread has been created using Environment::createThread() method.

threadInfoPointer to HF_ThreadInfo struct.

The documentation for this class was generated from the following file: