@@ -2,7 +2,7 @@ | |||||
noinst_LIBRARIES = liblol.a | noinst_LIBRARIES = liblol.a | ||||
liblol_a_SOURCES = \ | liblol_a_SOURCES = \ | ||||
core.h tiler.cpp tiler.h dict.cpp dict.h \ | core.h tiler.cpp tiler.h dict.cpp dict.h debug/debug.h \ | ||||
audio.cpp audio.h scene.cpp scene.h font.cpp font.h layer.cpp layer.h \ | audio.cpp audio.h scene.cpp scene.h font.cpp font.h layer.cpp layer.h \ | ||||
map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h lolgl.h \ | map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h lolgl.h \ | ||||
tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h log.cpp log.h \ | tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h log.cpp log.h \ | ||||
@@ -71,6 +71,7 @@ static inline int isnan(float f) | |||||
#include "thread/thread.h" | #include "thread/thread.h" | ||||
// Static classes | // Static classes | ||||
#include "debug/debug.h" | |||||
#include "log.h" | #include "log.h" | ||||
#include "platform.h" | #include "platform.h" | ||||
#include "video.h" | #include "video.h" | ||||
@@ -0,0 +1,32 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2012 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. | |||||
// | |||||
// | |||||
// Debug utilities | |||||
// --------------- | |||||
// | |||||
#if !defined __LOL_DEBUG_H__ | |||||
#define __LOL_DEBUG_H__ | |||||
#include "entity.h" | |||||
namespace lol | |||||
{ | |||||
static void Abort() | |||||
{ | |||||
*(int *)NULL = 0; | |||||
} | |||||
} /* namespace lol */ | |||||
#endif // __LOL_DEBUG_H__ | |||||
@@ -97,7 +97,8 @@ VertexDeclaration::~VertexDeclaration() | |||||
D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data; | D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data; | ||||
# endif | # endif | ||||
vdecl->Release(); | if (FAILED(vdecl->Release())) | ||||
Abort(); | |||||
#else | #else | ||||
#endif | #endif | ||||
@@ -112,7 +113,8 @@ void VertexDeclaration::Bind() | |||||
D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data; | D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data; | ||||
# endif | # endif | ||||
g_d3ddevice->SetVertexDeclaration(vdecl); | if (FAILED(g_d3ddevice->SetVertexDeclaration(vdecl))) | ||||
Abort(); | |||||
#else | #else | ||||
/* FIXME: Nothing to do? */ | /* FIXME: Nothing to do? */ | ||||
#endif | #endif | ||||
@@ -121,11 +123,13 @@ void VertexDeclaration::Bind() | |||||
void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | ||||
{ | { | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) | ||||
Abort(); | |||||
switch (type) | switch (type) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count); | if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count))) | ||||
Abort(); | |||||
break; | break; | ||||
} | } | ||||
#else | #else | ||||
@@ -193,7 +197,10 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | |||||
/* Now we know the stream index and the element stride */ | /* Now we know the stream index and the element stride */ | ||||
/* FIXME: precompute most of the crap above! */ | /* FIXME: precompute most of the crap above! */ | ||||
if (stream >= 0) | if (stream >= 0) | ||||
g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride); | { | ||||
if (FAILED(g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride))) | |||||
Abort(); | |||||
} | |||||
#else | #else | ||||
glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | ||||
ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ||||
@@ -334,7 +341,8 @@ void VertexDeclaration::Initialize() | |||||
D3DVertexDeclaration *vdecl; | D3DVertexDeclaration *vdecl; | ||||
# endif | # endif | ||||
g_d3ddevice->CreateVertexDeclaration(elements, &vdecl); | if (FAILED(g_d3ddevice->CreateVertexDeclaration(elements, &vdecl))) | ||||
Abort(); | |||||
m_data = vdecl; | m_data = vdecl; | ||||
#else | #else | ||||
@@ -365,8 +373,9 @@ VertexBuffer::VertexBuffer(size_t size) | |||||
: m_data(new VertexBufferData) | : m_data(new VertexBufferData) | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL, | if (FAILED(g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL, | ||||
D3DPOOL_MANAGED, &m_data->m_vbo, NULL); | D3DPOOL_MANAGED, &m_data->m_vbo, NULL))) | ||||
Abort(); | |||||
new uint8_t[size]; | new uint8_t[size]; | ||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
glGenBuffers(1, &m_data->m_vbo); | glGenBuffers(1, &m_data->m_vbo); | ||||
@@ -378,7 +387,8 @@ VertexBuffer::VertexBuffer(size_t size) | |||||
VertexBuffer::~VertexBuffer() | VertexBuffer::~VertexBuffer() | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
m_data->m_vbo->Release(); | if (FAILED(m_data->m_vbo->Release())) | ||||
Abort(); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
glDeleteBuffers(1, &m_data->m_vbo); | glDeleteBuffers(1, &m_data->m_vbo); | ||||
delete[] m_data->m_memory; | delete[] m_data->m_memory; | ||||
@@ -390,7 +400,7 @@ void *VertexBuffer::Lock(size_t offset, size_t size) | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
void *ret; | void *ret; | ||||
if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0))) | if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0))) | ||||
exit(0); | Abort(); | ||||
return ret; | return ret; | ||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
return m_data->m_memory + offset; | return m_data->m_memory + offset; | ||||
@@ -400,7 +410,8 @@ void *VertexBuffer::Lock(size_t offset, size_t size) | |||||
void VertexBuffer::Unlock() | void VertexBuffer::Unlock() | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
m_data->m_vbo->Unlock(); | if (FAILED(m_data->m_vbo->Unlock())) | ||||
Abort(); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); | glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); | ||||
glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | ||||
@@ -102,14 +102,17 @@ void SdlApp::Run() | |||||
while (!Ticker::Finished()) | while (!Ticker::Finished()) | ||||
{ | { | ||||
#if defined USE_SDL && defined USE_D3D9 | #if defined USE_SDL && defined USE_D3D9 | ||||
g_d3ddevice->BeginScene(); | if (FAILED(g_d3ddevice->BeginScene())) | ||||
Abort(); | |||||
#endif | #endif | ||||
/* Tick the renderer, show the frame and clamp to desired framerate. */ | /* Tick the renderer, show the frame and clamp to desired framerate. */ | ||||
Ticker::TickDraw(); | Ticker::TickDraw(); | ||||
#if defined USE_SDL | #if defined USE_SDL | ||||
# if defined USE_D3D9 | # if defined USE_D3D9 | ||||
g_d3ddevice->EndScene(); | if (FAILED(g_d3ddevice->EndScene())) | ||||
g_d3ddevice->Present(NULL, NULL, NULL, NULL); | Abort(); | ||||
if (FAILED(g_d3ddevice->Present(NULL, NULL, NULL, NULL))) | |||||
Abort(); | |||||
# else | # else | ||||
SDL_GL_SwapBuffers(); | SDL_GL_SwapBuffers(); | ||||
# endif | # endif | ||||
@@ -18,22 +18,11 @@ | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
# define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
# include <windows.h> | # include <windows.h> | ||||
# if defined USE_D3D9 | |||||
# define FAR | |||||
# define NEAR | |||||
# include <d3d9.h> | |||||
# endif | |||||
#endif | #endif | ||||
#include "core.h" | #include "core.h" | ||||
#include "lolgl.h" | #include "lolgl.h" | ||||
#if defined USE_D3D9 | |||||
extern IDirect3DDevice9 *g_d3ddevice; | |||||
#elif defined _XBOX | |||||
extern D3DDevice *g_d3ddevice; | |||||
#endif | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -106,6 +95,7 @@ Scene::~Scene() | |||||
for (int i = 0; i < data->nbufs; i++) | for (int i = 0; i < data->nbufs; i++) | ||||
delete data->bufs[i]; | delete data->bufs[i]; | ||||
free(data->bufs); | free(data->bufs); | ||||
delete data->m_vdecl; | delete data->m_vdecl; | ||||
delete data; | delete data; | ||||
} | } | ||||
@@ -228,9 +228,10 @@ void Video::Clear() | |||||
{ | { | ||||
ivec2 size = GetSize(); | ivec2 size = GetSize(); | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | if (FAILED(VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | ||||
| D3DCLEAR_STENCIL, | | D3DCLEAR_STENCIL, | ||||
VideoData::clear_color, 1.0f, 0); | VideoData::clear_color, 1.0f, 0))) | ||||
Abort(); | |||||
#else | #else | ||||
glViewport(0, 0, size.x, size.y); | glViewport(0, 0, size.x, size.y); | ||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||||
@@ -86,8 +86,8 @@ public: | |||||
} | } | ||||
m_shader->Bind(); | m_shader->Bind(); | ||||
m_vdecl->Bind(); | |||||
m_vdecl->SetStream(m_vbo, m_coord); | m_vdecl->SetStream(m_vbo, m_coord); | ||||
m_vdecl->Bind(); | |||||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1); | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
} | } | ||||
@@ -167,9 +167,9 @@ public: | |||||
#elif defined _XBOX || defined USE_D3D9 | #elif defined _XBOX || defined USE_D3D9 | ||||
int16_t *indices; | int16_t *indices; | ||||
if (FAILED(g_d3ddevice->CreateIndexBuffer(sizeof(m_indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL))) | if (FAILED(g_d3ddevice->CreateIndexBuffer(sizeof(m_indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL))) | ||||
exit(0); | Abort(); | ||||
if (FAILED(m_ibo->Lock(0, 0, (void **)&indices, 0))) | if (FAILED(m_ibo->Lock(0, 0, (void **)&indices, 0))) | ||||
exit(0); | Abort(); | ||||
memcpy(indices, m_indices, sizeof(m_indices)); | memcpy(indices, m_indices, sizeof(m_indices)); | ||||
m_ibo->Unlock(); | m_ibo->Unlock(); | ||||
#else | #else | ||||
@@ -180,16 +180,21 @@ public: | |||||
m_ready = true; | m_ready = true; | ||||
} | } | ||||
Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||||
m_shader->Bind(); | m_shader->Bind(); | ||||
m_shader->SetUniform(m_mvp, m_matrix); | m_shader->SetUniform(m_mvp, m_matrix); | ||||
m_vdecl->Bind(); | |||||
m_vdecl->SetStream(m_vbo, m_coord); | m_vdecl->SetStream(m_vbo, m_coord); | ||||
m_vdecl->SetStream(m_cbo, m_color); | m_vdecl->SetStream(m_cbo, m_color); | ||||
m_vdecl->Bind(); | |||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) | ||||
g_d3ddevice->SetIndices(m_ibo); | Abort(); | ||||
g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices)); | if (FAILED(g_d3ddevice->SetIndices(m_ibo))) | ||||
Abort(); | |||||
if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices)))) | |||||
Abort(); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | ||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | ||||
int size; | int size; | ||||
@@ -133,6 +133,7 @@ | |||||
<ClInclude Include="..\src\debug\record.h" /> | <ClInclude Include="..\src\debug\record.h" /> | ||||
<ClInclude Include="..\src\debug\sphere.h" /> | <ClInclude Include="..\src\debug\sphere.h" /> | ||||
<ClInclude Include="..\src\debug\stats.h" /> | <ClInclude Include="..\src\debug\stats.h" /> | ||||
<ClInclude Include="..\src\debug\debug.h" /> | |||||
<ClInclude Include="..\src\dict.h" /> | <ClInclude Include="..\src\dict.h" /> | ||||
<ClInclude Include="..\src\eglapp.h" /> | <ClInclude Include="..\src\eglapp.h" /> | ||||
<ClInclude Include="..\src\emitter.h" /> | <ClInclude Include="..\src\emitter.h" /> | ||||