Login Action Required

The NinevehGL Forum uses a new concept of "socialized forum" or as we like to say "Tweet Forum".


Here is the deal:
  1. No new registration is required. Just sign in with your Twitter account and authorize the NinevehGL Forum.
  2. Once you’re in, you'll be able to "Follow a Thread", that means every time that thread receive a new post or update you'll receive a mention on your twitter.
  3. Besides, you can enable "Auto Share", then every new post and/or thread you make will be tweeted on your timeline. (By default, auto-share is enabled only for your threads)

Forum Rules:

1. We understand human comunication can become "hot" sometimes. So some insults and bad words ARE allowed. Just don't push too much being an asshole all the time.

2. SPAMMERS are not allowed. There are penalties for this kind of user and they can be banned forever.

3. You can report other users, if you judge necessary. An user reported many times by many people can also be banned forever. However you can also receive penalties for report deliberately for no apparent reason.

If there is a similar thread title, make sure the other one doesn't already have the answer you're looking for.

This forum uses the BBCode (Bulletin Board Code), here are some instructions:

Bold: [b]text[/b]
Italic: [i]text[/i]
Underline: [u]text[/u]

Code: [code]text[/code]
Quote:
[quote=@username]text[/quote]
[quote]text[/quote]

List:
[ul] [*]item [/ul]
[ol] [*]item [/ol]

URL:
[url]http://url.com[/url]
[url=http://url.com]text[/url]

Image:
[img]http://imageurl.com[/img]

Embed (videos, code, 3D):
[embed]http://url.com[/embed]

Welcome to the NinevehGL's world!
NinevehGL is a 3D engine forged with pure Obj-C.
Welcome to the
Forum!
Hello, Guest.

Your current vote:

You can change your vote many times. But it's still one single vote.

Is there any way to make my own game loop?
Vote this thread:


@PetrBodnar

Posts: 17

NGLNewbie

Mon, Aug 27 2012


Is there any way for me in my application to create my own game loop and use NinevehGL objects (meshes,camera etc. ) and NinevehGL render?

Something like that:

@interface MyViewController : UIViewController <NGLViewDelegate>

@property (retain) NGLCamera *camera;
@property (retain) NGLMesh *mesh;

@end

...

const uint64_t TICKS_PER_SECOND = 25;
const uint64_t SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const uint64_t MAX_FRAMESKIP = 5;

static uint64_t next_game_tick;

- (void)gameLoop {
    next_game_tick = GetCurrentMilliseconds();
    int loops;
    uint64_t t;
    bool game_is_running = true;
    while( game_is_running ) {
        loops = 0;
        t = GetCurrentMilliseconds();
        while( t > next_game_tick && loops < MAX_FRAMESKIP) {
            // Updating
            {
                self.currentMeshRotation = ROTATION_SPEED;
                self.currentCameraZ = MOVE_CAMERA_Z_SPEED;
                                ...
            }
            next_game_tick = SKIP_TICKS;
            loops ;
            t = GetCurrentMilliseconds();
        }

        [self draw];
    }
}

- (void)draw {
        long millis = GetCurrentMilliseconds();
        double  interpolation = (double)( millis SKIP_TICKS - next_game_tick ) / (double)( SKIP_TICKS );
        
self.rotatingMesh.rotateY = self.currentMeshRotation ROTATION_SPEED * interpolation;
        self.camera.z = self.currentCameraZ MOVE_CAMERA_Z_SPEED * interpolation;

        // render using NinevehGL
                // ???
}
0% like this - 0/0

@PetrBodnar

Posts: 17

NGLNewbie

Mon, Aug 27 2012


Sorry, something with text formatting.
Please remove my first post.
Is there any way for me in my application to create my own game loop and use NinevehGL objects (meshes,camera etc. ) and NinevehGL render?

Someting like that:


@interface MyView : NGLView

@property (retain) NGLCamera *camera;
@property (retain) NGLMesh *mesh;

@end

...

const uint64_t TICKS_PER_SECOND = 25;
const uint64_t SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const uint64_t MAX_FRAMESKIP = 5;



static uint64_t next_game_tick;

- (void)gameLoop {
next_game_tick = GetCurrentMilliseconds();
int loops;
uint64_t t;
bool game_is_running = true;
while( game_is_running ) {
loops = 0;
t = GetCurrentMilliseconds();
while( t > next_game_tick && loops < MAX_FRAMESKIP) {
// Updating
{
self.currentMeshRotation = ROTATION_SPEED;
self.currentCameraZ = MOVE_CAMERA_Z_SPEED;
...
}
next_game_tick = SKIP_TICKS;
loops ;
t = GetCurrentMilliseconds();
}

[self draw];
}
}

- (void)draw {
long millis = GetCurrentMilliseconds();
double interpolation = (double)( millis SKIP_TICKS - next_game_tick ) / (double)( SKIP_TICKS );

self.rotatingMesh.rotateY = self.currentMeshRotation ROTATION_SPEED * interpolation;
_camera.x = self.currentCameraZ MOVE_CAMERA_Z_SPEED * interpolation;

// render using NinevehGL
// ???
}
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Mon, Aug 27 2012


In response to: @PetrBodnar

Hello buddy.

Well, in theory yes, you can. But I don't know if this is a good idea, since you can change the NinevehGL framerate as you wish.

If you create another loop you can get stuck into another problem, sending multiple render commands to NinevehGL and creating a large queue.

What's your intention creating another loop?
0% like this - 0/0

@PetrBodnar

Posts: 17

NGLNewbie

Tue, Aug 28 2012


I want to achieve smooth animations at FPS 35-45 (I described my problems with NGLTween and not smooth animations in another thread on this forum). I want to try to create game loop with interpolation for this.
I have tried to change fps (with nglGlobalFPS ) to 35-40, so it was "fixed", but animations remains not smooth.
I think that if I can create loop with interpolation, I can achieve smooth animations on such fps.

@dineybomfim said:


If you create another loop you can get stuck into another problem, sending multiple render commands to NinevehGL and creating a large queue.

What do you mean? Is there any way to avoid this problem? May be, some "direct" API of NinevehGL?
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Tue, Aug 28 2012


In response to: @PetrBodnar

Well buddy,

So don't use NGLTween, make the animations by your own inside the NinevehGL render loop.
Because creating another loop will not change the NGLTween performance, it's bound to the NinevehGL render loop. So it's affected by the NinevehGL render performance.
0% like this - 0/0

@PetrBodnar

Posts: 17

NGLNewbie

Tue, Aug 28 2012


In response to: @dineybomfim

Sorry that I don't clarified my question
I meant that in my game loop I wish to realize my own update logic and animation, without NGLTween.
All I need is a some render API of NinevehGL, without using the NinevehGL render loop.
Is there any possibility in engine for this?
Thank you!
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Tue, Aug 28 2012


In response to: @PetrBodnar

Unfortunately, there isn't.

To make a NinevehGL render, you must follow the NinevehGL render loop.

But this doesn't exclude the possibility of creating another loop just for your game commands.
0% like this - 0/0

@adameisfeld

Posts: 41

NGLUser

Tue, Aug 28 2012


In response to: @PetrBodnar

Why can't you just calculate the time elapsed between the current drawView call and the last drawView call and use this to interpolate your animation?

"Game loop" logic doesn't mix well with Object-Oriented programming, they're really two different styles. In a game loop system you tend to figure out what you need to figure out each loop, and then go on about figuring it out in that loop as well. The beauty of object-oriented programming is you don't need to worry about figuring everything out every single loop.
100% like this - 1/1

@PetrBodnar

Posts: 17

NGLNewbie

Wed, Aug 29 2012


In response to: @adameisfeld

Ok, thanks! I will try to do that.
0% like this - 0/0
Technology

NinevehGL is a 3D engine built right on top of OpenGL ES and it uses all the programmable pipeline power, making it easy for you to create great application with shaders.

Share on


Follow NinevehGL
Fastest way to contact us:

Copyright © 2011 db-in. All rights reserved.