Skip to content

Commit

Permalink
Preparing audio streaming, allow not-destroy-while-iterating.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Aug 29, 2012
1 parent d963e92 commit 0b21dbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/ldkit/Actor.ooc
Expand Up @@ -3,7 +3,7 @@ Actor: class {

init: func {}

update: func (delta: Float) {
update: func (delta: Float) -> Bool {
"Override %s#update! (delta = %.2f)" printfln(class name, delta)
}

Expand All @@ -21,7 +21,7 @@ ActorClosure: class extends Actor {

}

update: func (delta: Float) {
update: func (delta: Float) -> Bool {
f(delta)
}

Expand Down
15 changes: 13 additions & 2 deletions source/ldkit/Engine.ooc
Expand Up @@ -30,9 +30,10 @@ Engine: class {
ticks = LTime getTicks()

// two physics simulation
for(a in actors) a update(delta * 0.5)
updateActors(delta * 0.5)

if (!slomo) {
for(a in actors) a update(delta * 0.5)
updateActors(delta * 0.5)
}
ui update()

Expand All @@ -44,6 +45,16 @@ Engine: class {
}
}

updateActors: func (realDelta: Float) {
iter := actors iterator()
while (iter hasNext?()) {
actor := iter next()
if (actor update(realDelta)) {
iter remove()
}
}
}

add: func (actor: Actor) {
actors add(actor)
}
Expand Down
10 changes: 7 additions & 3 deletions source/ldkit/Sound.ooc
Expand Up @@ -36,11 +36,13 @@ Source: class {
match als {
case AL_STOPPED => SourceState STOPPED
case => SourceState PLAYING
// TODO: handle other cases?
}
}

update: func {
if (sample streaming) {
}

if(getState() == SourceState STOPPED) {
if(autofree) {
// "Freeing source %d, because already stopped" printfln(sourceID)
Expand Down Expand Up @@ -73,8 +75,10 @@ Sample: class {

path: String

streaming: Bool

// loads the sample
init: func (=path) {
init: func (=path, =streaming) {
if (path endsWith?(".ogg")) {
loadOgg(path)
} else {
Expand Down Expand Up @@ -172,7 +176,7 @@ Boombox: class {
cache get(aPath)
} else {
logger info("Loading audio file... %s" format(path))
s := Sample new(aPath)
s := Sample new(aPath, false)
cache put(aPath, s)
s
}
Expand Down

0 comments on commit 0b21dbd

Please sign in to comment.