Jump to content

  • Log In with Google      Sign In   
  • Create Account

noodleBowl

Member Since 08 Sep 2013
Offline Last Active Feb 01 2016 09:06 AM

Topics I've Started

User defined functions?

16 December 2015 - 03:31 PM

I was wondering if there is a way to have user defined functions?
 
Here is my situation, I'm trying my hand at multi-platform code.

I have a source file that has multiple main functions meant for their specific platform. When I compile a specific platform, the main function for that platform will be the one available and act as the programs entry point. So for example:
 
Desktop compile would have and use the typical main:

void main()
{
   //Program entry point
}

 
Where compiling for Android would use and have this main function:

ANativeActivity_createFunc AndroidStart;
void AndroidStart (ANativeActivity *activity, void *savedState, size_t savedStateSize)
{
   //Program entry point
}

Now I'm looking to have some user defined functions for Update and Render. Where these are automatically called by the internals of my code, but are what the user needs to have. Something like:

 

 
//In the internals of on my android application
void MainThreadRun()
{
     while(running)
     {
            HandlePollData();
 
            //User functions that the user made
            UserDefinedUpdate();
            UserDefinedRender();
     }
}
 

 

I was hoping I could do something like an extern method, but seeing that I want to package my code up as a SO / DLL library. Making methods like those and declaring them extern cause linker errors. Which makes sense cause they would not be declared in my code.

 

So what can I do? What are some better options?


Vector Push Back?

09 December 2015 - 10:03 AM

I have a quick question about std::vector and its push_back function
 
If I have this data class:
class DataBlock
{
   int blockID;
   float data[25000];
};

What happens, memory wise and with the block variable, when I do
//In some function
if(needNewDataBlock == true)
{
   DataBlock block;
   dataBlockVector.push_back(block);
}


MyClass myClass VS myClass = new MyClass()

20 November 2015 - 08:39 AM

I was wondering if someone could tell me the difference between:

MyClass class;

And
 

MyClass *myClass;
myClass = new MyClass();

Other than the second block of code is making a dynamic memory allocation and that I must delete it when I'm done with it otherwise I'll suffer memory leaks.

 

But what I mean is which one should I be using the most? Does it matter even?

Would it be bad to have all of my custom classes created using the dynamic memory way?

 


Android Native Window Create, Destroy, and OpenGL Context

18 November 2015 - 03:35 PM

This might be rough to explain, but I'm working in NDK using the Android Native activity. And Im wondering about the callbacks:
onNativeWindowCreated (ANativeActivity *activity, ANativeWindow *window)
onNativeWindowDestroyed (ANativeActivity *activity, ANativeWindow *window)
And their relation with an OpengGL context
More specifically those calls and when I should be using calls to OpenGL and creating rendering systems like a SpriteBatcher

Currently in my activity, I have it setup where the onNativeWindowCreated callback triggers the creation of a EGLDisplay, which in turn creates an OpenGL context. In addition, this trigger (the onNativeWindowCreated one) also creates my SpriteBatcher rendering class.
//In Trigger for onNativeWindowCreated 
//Code that creates and sets up opengl
CreateEGLDisplay();

//Code that creates everything needed by the sprite batcher 
//(OpenGL calls happen here, creation of buffers and etc)
spriteBatcher = new SpriteBatcher(); 

And the onNativeWindowDestroyed callback triggers a method to destroy said EGLDisplay and the sprite batcher.
//In Trigger for onNativeWindowDestroyed  
//Code that creates and sets up opengl
DestroyEGLDisplay();

//Free up the sprite batcher
delete spriteBatcher;
So I'm wondering is this how I should I be handling classes and things that make OpenGL calls? I know you need a OpenGL context in order to make those calls. But...

Since I'm destroying the context when the window is killed (which I assume is perfectly normal or what I should be doing) I'm wondering how should OpenGL textures, buffers, and etc are handled. Do I just need to recreate them each time? Is this normal? Should I be doing it differently?

Void Pointers as variables?

17 November 2015 - 10:54 PM

I was wondering about this:
 
I have this class called ApplicationWindow
class ApplicationWindow
{
public:
	ApplicationWindow();
	virtual ~ApplicationWindow();
	void *GetWindow();
	int32_t GetWidth();
	int32_t GetHeight();

protected:
	void *windowHandle;
	int32_t width;
	int32_t height;
};
And I also have this class EGLDisplayWindow which will inherit ApplicationWindow
class EGLDisplayWindow : public ApplicationWindow
{
public:
	EGLDisplayWindow();
	~EGLDisplayWindow();
	void CreateWindow(void *windowHandle);

private:
	void CreateAndroidWindow();
	void CreateIOSWindow();
	void DestroyWindow();


};

As you can see ApplicationWindow has a private variable called windowHandle and a method called GetWindow()
When a EGLDisplayWindow is created my idea is to create the proper window needed by each application. Then store that "window" into the windowHandle variable, where it can be accessed using the GetWindow() method

Is this a bad idea (including the void pointer part)? Is there a better solution?

PARTNERS