Commit ac95c302 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Replace the light list with a standard Wine list.

parent f50ad122
...@@ -416,8 +416,7 @@ struct IDirect3DLightImpl ...@@ -416,8 +416,7 @@ struct IDirect3DLightImpl
DWORD dwLightIndex; DWORD dwLightIndex;
/* Chained list used for adding / removing from viewports */ struct list entry;
IDirect3DLightImpl *next;
}; };
/* Helper functions */ /* Helper functions */
...@@ -473,9 +472,7 @@ struct IDirect3DViewportImpl ...@@ -473,9 +472,7 @@ struct IDirect3DViewportImpl
} viewports; } viewports;
struct list entry; struct list entry;
struct list light_list;
/* Lights list */
IDirect3DLightImpl *lights;
/* Background material */ /* Background material */
IDirect3DMaterialImpl *background; IDirect3DMaterialImpl *background;
......
...@@ -36,18 +36,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw); ...@@ -36,18 +36,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
* activates the viewport using IDirect3DDevice7::SetViewport * activates the viewport using IDirect3DDevice7::SetViewport
* *
*****************************************************************************/ *****************************************************************************/
void viewport_activate(IDirect3DViewportImpl* This, BOOL ignore_lights) { void viewport_activate(IDirect3DViewportImpl *This, BOOL ignore_lights)
IDirect3DLightImpl* light; {
D3DVIEWPORT7 vp; D3DVIEWPORT7 vp;
if (!ignore_lights) { if (!ignore_lights)
/* Activate all the lights associated with this context */ {
light = This->lights; IDirect3DLightImpl *light;
while (light) /* Activate all the lights associated with this context */
LIST_FOR_EACH_ENTRY(light, &This->light_list, IDirect3DLightImpl, entry)
{ {
light_activate(light); light_activate(light);
light = light->next;
} }
} }
...@@ -749,8 +749,7 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, ...@@ -749,8 +749,7 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface,
This->map_lights |= 1<<i; This->map_lights |= 1<<i;
/* Add the light in the 'linked' chain */ /* Add the light in the 'linked' chain */
lpDirect3DLightImpl->next = This->lights; list_add_head(&This->light_list, &lpDirect3DLightImpl->entry);
This->lights = lpDirect3DLightImpl;
IDirect3DLight_AddRef(lpDirect3DLight); IDirect3DLight_AddRef(lpDirect3DLight);
/* Attach the light to the viewport */ /* Attach the light to the viewport */
...@@ -782,33 +781,29 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, ...@@ -782,33 +781,29 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface,
IDirect3DLight *lpDirect3DLight) IDirect3DLight *lpDirect3DLight)
{ {
IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface;
IDirect3DLightImpl *lpDirect3DLightImpl = (IDirect3DLightImpl *)lpDirect3DLight; IDirect3DLightImpl *l = (IDirect3DLightImpl *)lpDirect3DLight;
IDirect3DLightImpl *cur_light, *prev_light = NULL;
TRACE("iface %p, light %p.\n", iface, lpDirect3DLight); TRACE("iface %p, light %p.\n", iface, lpDirect3DLight);
EnterCriticalSection(&ddraw_cs); EnterCriticalSection(&ddraw_cs);
cur_light = This->lights;
while (cur_light != NULL) { if (l->active_viewport != This)
if (cur_light == lpDirect3DLightImpl)
{ {
light_deactivate(lpDirect3DLightImpl); WARN("Light %p active viewport is %p.\n", l, l->active_viewport);
if (!prev_light) This->lights = cur_light->next;
else prev_light->next = cur_light->next;
/* Detach the light from the viewport. */
cur_light->active_viewport = NULL;
IDirect3DLight_Release((IDirect3DLight *)cur_light);
--This->num_lights;
This->map_lights &= ~(1 << lpDirect3DLightImpl->dwLightIndex);
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return DDERR_INVALIDPARAMS;
}
prev_light = cur_light;
cur_light = cur_light->next;
} }
light_deactivate(l);
list_remove(&l->entry);
l->active_viewport = NULL;
IDirect3DLight_Release(lpDirect3DLight);
--This->num_lights;
This->map_lights &= ~(1 << l->dwLightIndex);
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return D3D_OK;
} }
/***************************************************************************** /*****************************************************************************
...@@ -831,7 +826,9 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, ...@@ -831,7 +826,9 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface,
DWORD dwFlags) DWORD dwFlags)
{ {
IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface; IDirect3DViewportImpl *This = (IDirect3DViewportImpl *)iface;
IDirect3DLightImpl *cur_light, *prev_light = NULL; IDirect3DLightImpl *l = (IDirect3DLightImpl *)lpDirect3DLight;
struct list *entry;
HRESULT hr;
TRACE("iface %p, light %p, next_light %p, flags %#x.\n", TRACE("iface %p, light %p, next_light %p, flags %#x.\n",
iface, lpDirect3DLight, lplpDirect3DLight, dwFlags); iface, lpDirect3DLight, lplpDirect3DLight, dwFlags);
...@@ -839,47 +836,50 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface, ...@@ -839,47 +836,50 @@ IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface,
if (!lplpDirect3DLight) if (!lplpDirect3DLight)
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
*lplpDirect3DLight = NULL;
EnterCriticalSection(&ddraw_cs); EnterCriticalSection(&ddraw_cs);
cur_light = This->lights; switch (dwFlags)
{
switch (dwFlags) {
case D3DNEXT_NEXT: case D3DNEXT_NEXT:
if (!lpDirect3DLight) { if (!l || l->active_viewport != This)
LeaveCriticalSection(&ddraw_cs); {
return DDERR_INVALIDPARAMS; if (l)
} WARN("Light %p active viewport is %p.\n", l, l->active_viewport);
while (cur_light != NULL) { entry = NULL;
if (cur_light == (IDirect3DLightImpl *)lpDirect3DLight) {
*lplpDirect3DLight = (IDirect3DLight*)cur_light->next;
break;
}
cur_light = cur_light->next;
} }
else
entry = list_next(&This->light_list, &l->entry);
break; break;
case D3DNEXT_HEAD: case D3DNEXT_HEAD:
*lplpDirect3DLight = (IDirect3DLight*)This->lights; entry = list_head(&This->light_list);
break; break;
case D3DNEXT_TAIL: case D3DNEXT_TAIL:
while (cur_light != NULL) { entry = list_tail(&This->light_list);
prev_light = cur_light;
cur_light = cur_light->next;
}
*lplpDirect3DLight = (IDirect3DLight*)prev_light;
break; break;
default: default:
ERR("Unknown flag %d\n", dwFlags); entry = NULL;
WARN("Invalid flags %#x.\n", dwFlags);
break; break;
} }
if (*lplpDirect3DLight) if (entry)
{
*lplpDirect3DLight = (IDirect3DLight *)LIST_ENTRY(entry, IDirect3DLightImpl, entry);
IDirect3DLight_AddRef(*lplpDirect3DLight); IDirect3DLight_AddRef(*lplpDirect3DLight);
hr = D3D_OK;
}
else
{
*lplpDirect3DLight = NULL;
hr = DDERR_INVALIDPARAMS;
}
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
return *lplpDirect3DLight ? D3D_OK : DDERR_INVALIDPARAMS; return hr;
} }
/***************************************************************************** /*****************************************************************************
...@@ -1131,4 +1131,5 @@ void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw) ...@@ -1131,4 +1131,5 @@ void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw)
viewport->ref = 1; viewport->ref = 1;
viewport->ddraw = ddraw; viewport->ddraw = ddraw;
viewport->use_vp2 = 0xff; viewport->use_vp2 = 0xff;
list_init(&viewport->light_list);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment