Explorar el Código

core: start working on the Emcee class.

legacy
Sam Hocevar sam hace 13 años
padre
commit
3d3ec36548
Se han modificado 9 ficheros con 158 adiciones y 2 borrados
  1. +1
    -1
      src/Makefile.am
  2. +2
    -0
      src/application/application.cpp
  3. +1
    -0
      src/core.h
  4. +82
    -0
      src/emcee.cpp
  5. +41
    -0
      src/emcee.h
  6. +11
    -0
      src/entity.cpp
  7. +13
    -0
      src/entity.h
  8. +0
    -1
      src/thread/threadbase.h
  9. +7
    -0
      test/debug/sandbox.cpp

+ 1
- 1
src/Makefile.am Ver fichero

@@ -11,7 +11,7 @@ liblol_a_SOURCES = \
text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \
worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \
platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \
real.cpp real.h \
real.cpp real.h emcee.cpp emcee.h \
\
lol/unit.h \
\


+ 2
- 0
src/application/application.cpp Ver fichero

@@ -59,6 +59,7 @@ class ApplicationData

Application::Application(char const *name, ivec2 resolution, float framerate)
{
Emcee::Setup();
data = new ApplicationData(name, resolution, framerate);
}

@@ -75,6 +76,7 @@ void Application::Run()
Application::~Application()
{
delete data;
Emcee::Shutdown();
}

} /* namespace lol */


+ 1
- 0
src/core.h Ver fichero

@@ -103,6 +103,7 @@ static inline int isnan(float f)
#include "application/application.h"

// Managers
#include "emcee.h"
#include "ticker.h"
#include "forge.h"
#include "tiler.h"


+ 82
- 0
src/emcee.cpp Ver fichero

@@ -0,0 +1,82 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdlib>
#include <stdint.h>

#include "core.h"

namespace lol
{

/*
* Emcee implementation class
*/

static Thread *GameThread, *DrawThread;

static Queue gametick, drawtick;

static void *GameThreadMain(void *data)
{
while (!Ticker::Finished())
for (;;)
{
int tick = gametick.Pop();
if (!tick)
break;

Ticker::TickGame();

drawtick.Push(1);
}

drawtick.Push(0);
}

static void *DrawThreadMain(void *data)
{
for (;;)
{
int tick = drawtick.Pop();
if (!tick)
break;

Ticker::TickDraw();
}
}

void Emcee::Setup()
{
GameThread = new Thread(GameThreadMain, NULL);
DrawThread = new Thread(DrawThreadMain, NULL);
}

void Emcee::Shutdown()
{
}

void Emcee::SetState(Entity *entity, uint32_t state)
{

}

void Emcee::SetStateWhenMatch(Entity *entity, uint32_t state,
Entity *other_entity, uint32_t other_state)
{

}

} /* namespace lol */


+ 41
- 0
src/emcee.h Ver fichero

@@ -0,0 +1,41 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// The Emcee class
// ---------------
// The Emcee manages tasks and their dependencies
//

#if !defined __LOL_EMCEE_H__
#define __LOL_EMCEE_H__

#include <stdint.h>

#include "entity.h"

namespace lol
{

class Emcee
{
public:
static void Setup();
static void Shutdown();

static void SetState(Entity *entity, uint32_t state);
static void SetStateWhenMatch(Entity *entity, uint32_t state,
Entity *other_entity, uint32_t other_state);
};

} /* namespace lol */

#endif // __LOL_EMCEE_H__


+ 11
- 0
src/entity.cpp Ver fichero

@@ -68,5 +68,16 @@ void Entity::TickDraw(float deltams)
#endif
}

void Entity::SetState(uint32_t state)
{
Emcee::SetState(this, state);
}

void Entity::SetStateWhenMatch(uint32_t state,
Entity *other_entity, uint32_t other_state)
{
Emcee::SetStateWhenMatch(this, state, other_entity, other_state);
}

} /* namespace lol */


+ 13
- 0
src/entity.h Ver fichero

@@ -77,6 +77,19 @@ protected:
state;
#endif

// Emcee begin
private:
void SetState(uint32_t newstate);
void SetStateWhenMatch(uint32_t newstate,
Entity *other_entity, uint32_t other_state);
virtual uint32_t OnStateChanged(uint32_t newstate)
{
return m_state = newstate;
}

uint32_t m_state;
// Emcee end

private:
Entity *gamenext, *drawnext, *autonext;
int ref, autorelease, destroy;


+ 0
- 1
src/thread/threadbase.h Ver fichero

@@ -17,7 +17,6 @@
#define __LOL_THREADBASE_H__

#if defined __linux__ || defined __native_client__
# include <cstring>
# include <pthread.h>
#elif defined _WIN32
# include <windows.h>


+ 7
- 0
test/debug/sandbox.cpp Ver fichero

@@ -18,6 +18,13 @@

#include "core.h"

class Moo
{
Moo() {}

virtual int SetState(int state) { return state; }
};

using namespace std;
using namespace lol;



Cargando…
Cancelar
Guardar